PortfolioListViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. //
  2. // PDFListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 11/23/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PortfolioListViewController.h"
  9. #import "PortfolioListTableViewCell.h"
  10. #import "RANetwork.h"
  11. #import "RAPDFViewController.h"
  12. #import "MainViewController.h"
  13. #import "DefaultAppearance.h"
  14. #import "DefaultTableHeaderView.h"
  15. #import "SortItemViewController.h"
  16. #import "UIColor+JK_HEX.h"
  17. #import "TextUtils.h"
  18. #import "RAConvertor.h"
  19. @interface PortfolioListViewController ()
  20. @end
  21. @implementation PortfolioListViewController
  22. -(void) logout
  23. {
  24. self.offset = 0;
  25. self.limit = 25;
  26. [self.content_data removeAllObjects];
  27. [self refresh_ui];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.offset = 0;
  32. self.limit = 25;
  33. self.content_data = [[NSMutableArray alloc]init];
  34. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  35. ref.tag = 201 ;
  36. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  37. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  38. // ref.hidden = true;
  39. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  40. [self.table addSubview:ref];
  41. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  42. self.label_net_err.layer.borderWidth = 2.0;
  43. self.label_net_err.layer.cornerRadius=15;
  44. self.label_net_err.layer.masksToBounds=true;
  45. CGPoint center = self.mum.center;
  46. self.mum.frame = CGRectMake(0, 0, 100, 100);
  47. self.mum.center = center;
  48. self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5];
  49. self.mum.layer.cornerRadius = 5.0f;
  50. self.mum.layer.masksToBounds = YES;
  51. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  52. // tap.minimumPressDuration = 0.8; //定义按的时间
  53. [self.label_net_err addGestureRecognizer:tap];
  54. // Do any additional setup after loading the view.
  55. //#ifdef BUILD_UWAVER
  56. // self.navItem.title = @"View Hang Tags";
  57. //#endif
  58. }
  59. - (void)didReceiveMemoryWarning {
  60. [super didReceiveMemoryWarning];
  61. // Dispose of any resources that can be recreated.
  62. }
  63. #ifndef RA_NOTIFICATION
  64. -(void) reload_container_getdata:(bool) update_data
  65. {
  66. [super reload_container_getdata:update_data];
  67. if(update_data)
  68. {
  69. self.offset = 0;
  70. [self.content_data removeAllObjects];
  71. self.norefresh=true;
  72. [self loadpage];
  73. }
  74. else
  75. [self.table reloadData];
  76. }
  77. #endif
  78. - (void)viewWillAppear:(BOOL)animated
  79. {
  80. [super viewWillAppear:animated];
  81. // if(!self.norefresh)//避免 多次刷新
  82. // {
  83. // self.norefresh = true;
  84. // self.offset = 0;
  85. // [self.content_data removeAllObjects];
  86. // [self loadpage];
  87. //
  88. // }
  89. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  90. }
  91. -(void)manually_refresh
  92. {
  93. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  94. if(self.isrefreshing)
  95. {
  96. [reF endRefreshing];
  97. return;
  98. }
  99. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  100. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  101. }
  102. -(void)ReloadData
  103. {
  104. [self.content_data removeAllObjects];
  105. [self.table reloadData];
  106. // self.table_order.hidden = true;
  107. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  108. [reF endRefreshing];
  109. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  110. self.keywords=self.searchbar.text;
  111. self.offset = 0;
  112. // [self.content_data removeAllObjects];
  113. // [self.table_order reloadData];
  114. [self loadpage];
  115. // [self loadpage];
  116. }
  117. -(void) loadpage
  118. {
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. if(self.isrefreshing)
  121. return;
  122. self.label_net_err.hidden=true;
  123. self.isrefreshing=true;
  124. self.table.hidden =true;
  125. self.mum.center = self.view.center;
  126. self.mum.hidden = false;
  127. [self.mum startAnimating];
  128. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  129. NSMutableDictionary* content=nil;
  130. content=[[RANetwork request_PDFList:self.offset limit : self.limit keywords:self.keywords] mutableCopy];
  131. dispatch_async(dispatch_get_main_queue(), ^{
  132. [self.mum stopAnimating];
  133. int result=[[content valueForKey:@"result"] intValue];
  134. if(result==2||result==0)
  135. {
  136. self.table.hidden =false;
  137. int count = [[content valueForKey:@"count" ] intValue] ;
  138. // self.time_zone = [content valueForKey:@"time_zone" ];
  139. self.offset += count;
  140. for(int i=0;i<count;i++)
  141. {
  142. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  143. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  144. DebugLog(@"content_data: %@",self.content_data);
  145. }
  146. if(count<self.limit)
  147. {
  148. // int i =self.btnrefresh.state;
  149. self.load_more_hint=@"All loaded";
  150. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  151. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  152. }
  153. else
  154. {
  155. self.load_more_hint=@"Load more...";
  156. // self.btnrefresh.enabled = true;
  157. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  158. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  159. }
  160. [self.table reloadData ];
  161. }
  162. else if(result==RESULT_NET_ERROR)
  163. {
  164. self.label_net_err.hidden=false;
  165. self.table.hidden=true;
  166. }
  167. else
  168. {
  169. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Portfilio List" controller:self] ;
  170. }
  171. self.isrefreshing=false;
  172. });
  173. });
  174. });
  175. }
  176. - (void)loadmore
  177. {
  178. // self.btnrefresh.enabled = NO;
  179. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  180. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  181. [self loadpage];
  182. }
  183. /*
  184. #pragma mark - Navigation
  185. // In a storyboard-based application, you will often want to do a little preparation before navigation
  186. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  187. // Get the new view controller using [segue destinationViewController].
  188. // Pass the selected object to the new view controller.
  189. }
  190. */
  191. #pragma mark - Table view data source
  192. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  193. {
  194. return 66;
  195. }
  196. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  197. //{
  198. // return 0;
  199. //}
  200. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  201. //{
  202. // return 0;
  203. //}
  204. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  205. //{
  206. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  207. // return myView;
  208. //
  209. //}
  210. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  211. {
  212. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  213. if(value==nil)
  214. value=@"";
  215. unsigned long color = strtoul([value UTF8String],0,16);
  216. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  217. // myView.backgroundColor = UIColorFromRGB(color);
  218. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  219. myView.layer.shadowOffset = CGSizeMake(0, 0);
  220. myView.layer.shadowOpacity = 0.5;
  221. myView.layer.shadowRadius = 2.0;
  222. UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 75, 22)];
  223. namelabel.textColor=UIColorFromRGB(color);
  224. namelabel.backgroundColor = [UIColor clearColor];
  225. namelabel.text=NSLocalizedString(@"Name", nil);
  226. [namelabel sizeToFit];
  227. [myView addSubview:namelabel];
  228. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(173, 5.5, 130, 22)];
  229. // solabel.textColor=[UIColor whiteColor];
  230. // solabel.backgroundColor = [UIColor clearColor];
  231. // solabel.text=NSLocalizedString(@"Name", nil);
  232. // [solabel sizeToFit];
  233. // [myView addSubview:solabel];
  234. UILabel *notelabel = [[UILabel alloc] initWithFrame:CGRectMake(250, 11, 75, 22)];
  235. notelabel.textColor=UIColorFromRGB(color);
  236. notelabel.backgroundColor = [UIColor clearColor];
  237. notelabel.text=NSLocalizedString(@"Notes", nil);
  238. [notelabel sizeToFit];
  239. [myView addSubview:notelabel];
  240. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table.frame.size.width-163,11, 148, 22)];
  241. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  242. timelabel.textColor=UIColorFromRGB(color);
  243. timelabel.backgroundColor = [UIColor clearColor];
  244. timelabel.text=@"Create time";
  245. [timelabel sizeToFit];
  246. [myView addSubview:timelabel];
  247. myView.autoresizesSubviews=true;
  248. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  249. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  250. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  251. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  252. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  253. //
  254. return myView;
  255. }
  256. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  257. {
  258. return 44;
  259. }
  260. //
  261. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  262. // if(section==0)
  263. // return nil;
  264. // else
  265. // return @"detail section";
  266. //}
  267. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  268. {
  269. return 1;
  270. }
  271. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  272. {
  273. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  274. if( self.content_data.count==0)
  275. return 0;
  276. return self.content_data.count+1;
  277. }
  278. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  279. {
  280. // if(tableView==self.itemListTable)
  281. // {
  282. // if(indexPath.row>self.content_data.count)
  283. // {
  284. // int debug=true;
  285. // }
  286. // DebugLog(@"row %ld",(long)indexPath.row);
  287. if(indexPath.row==self.content_data.count)
  288. {
  289. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  290. UILabel *moreDataLabel=[[UILabel alloc] init];
  291. moreDataLabel.tag=200;
  292. moreDataLabel.text=self.load_more_hint;
  293. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  294. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  295. moreDataLabel.frame=CGRectMake(0, 10, self.table.bounds.size.width, 20);
  296. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  297. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  298. [moreCell.contentView addSubview:moreDataLabel];
  299. if([self.load_more_hint isEqualToString:@"Load more..."])
  300. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  301. // DebugLog(@"更多...");
  302. moreCell.backgroundColor = [UIColor whiteColor];
  303. return moreCell;
  304. }
  305. else
  306. {
  307. NSString *CellIdentifier = @"PDFListTableViewCell";
  308. PortfolioListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  309. // int _id= [[self.content_data[indexPath.row] valueForKey:@"_id"] intValue];
  310. NSString* name= [self.content_data[indexPath.row] valueForKey:@"tear_name"];
  311. NSString* note= [self.content_data[indexPath.row] valueForKey:@"tear_note"];
  312. NSString* create_time= [self.content_data[indexPath.row] valueForKey:@"create_time"];
  313. // NSString* type = [self.content_data[indexPath.row] valueForKey:@"type"] ;
  314. // NSString* file_name = [self.content_data[indexPath.row] valueForKey:@"file_name"];
  315. cell.labelName.text = name;
  316. cell.labelTime.text = create_time;
  317. cell.labelNote.text = note;
  318. // cell.labelType.text = type;
  319. // cell.labelprice.text=price;
  320. // cell.label_date.text=purchase_time;
  321. // cell.label_contact.text=customer_name;
  322. // cell.label_model.text = model_count;
  323. //
  324. // cell.label_status.text=status;
  325. cell.backgroundColor = [UIColor whiteColor];
  326. return cell;
  327. }
  328. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  329. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  330. // cell.bundle_item=combine_json;
  331. // NSString* img_url = [item_json valueForKey:@"img_url"];
  332. // NSString* description = [item_json valueForKey:@"description"];
  333. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  334. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  335. // NSString* currency = [item_json valueForKey:@"currency"];
  336. // int count =[[item_json valueForKey:@"count"] intValue];
  337. // double price =[[item_json valueForKey:@"price"] doubleValue];
  338. // // cell.labelAttribute.text = attribute;
  339. // cell.labelCurrency.text = currency;
  340. // cell.labelDescription.text = description;
  341. // // cell.labelIdentifier.text = identifier;
  342. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  343. //
  344. //
  345. //
  346. // [cell set_Count:count];
  347. // NSString* file_name=[img_url lastPathComponent];
  348. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  349. // if(img_data!=nil)
  350. // {
  351. //
  352. // UIImage * img =[UIImage imageWithData:img_data];
  353. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  354. // }
  355. // else
  356. // {
  357. //
  358. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  359. //
  360. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  361. //
  362. // dispatch_async(dispatch_get_main_queue(), ^{
  363. //
  364. //
  365. //
  366. // if(downloadimg_data!=nil)
  367. // {
  368. // [iSalesDB cache_img:downloadimg_data :file_name ];
  369. //
  370. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  371. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  372. // }
  373. //
  374. // });
  375. // });
  376. //
  377. //
  378. // }
  379. // }
  380. // else
  381. // {
  382. // NSString *CellIdentifier = @"OrderInfoListItem";
  383. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  384. // return cell;
  385. // }
  386. }
  387. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  388. {
  389. if(self.content_data.count== indexPath.row)
  390. return;
  391. NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  392. NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  393. if(url==nil)
  394. {
  395. NSMutableDictionary* params = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"off_params"]] mutableCopy];
  396. NSMutableDictionary* values = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"model_info"]] mutableCopy];
  397. params[@"replaceValue"]=values;
  398. params[@"tearsheetsId"]=[self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
  399. NSString* createpdf = [RANetwork create_portfolio:params];
  400. if(createpdf!=nil)
  401. url=createpdf;
  402. // if()
  403. }
  404. BOOL isLocalFile= [[self.content_data[indexPath.row] valueForKey:@"isLocalFile"] boolValue];
  405. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  406. ViewController.url = url;
  407. ViewController.canSave = false;
  408. ViewController.isLocalfile=isLocalFile;
  409. NSString* subject;
  410. // if (company.length==0) {
  411. // NSString* cur_time =[RAUtils current_date];
  412. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  413. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  414. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  415. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  416. if(customer_email.length>0)
  417. {
  418. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  419. // customer_email compo
  420. // [send_to addObject:customer_email];
  421. }
  422. ViewController.mail_to = send_to;
  423. // }
  424. // else
  425. // {
  426. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  427. // }
  428. NSString* lfilename = [TextUtils legalFilename:name];
  429. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",lfilename];
  430. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",lfilename];
  431. ViewController.mail_subject = subject;
  432. ViewController.hidenavi = false;
  433. [self.navigationController pushViewController:ViewController animated:YES];
  434. //[self.navigationController setNavigationBarHidden:NO animated:NO];
  435. }
  436. #pragma mark - searchBar delegate;
  437. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  438. {
  439. self.keywords=searchBar.text;
  440. self.offset = 0;
  441. [self.content_data removeAllObjects];
  442. [self loadpage];
  443. }
  444. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  445. {
  446. if([searchText isEqualToString:@""] && !self.reset)
  447. {
  448. DebugLog(@"clear");
  449. self.reset=true;
  450. self.keywords=nil;
  451. self.offset = 0;
  452. [self.content_data removeAllObjects];
  453. [self loadpage];
  454. }
  455. else
  456. self.reset = false;
  457. }
  458. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  459. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  460. {
  461. NSString* listid= [self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
  462. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  463. DebugLog(@"delete click");
  464. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure to remove portfolio?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  465. // // alert.tag = ALERT_DEL;
  466. // // alert.
  467. // [alert show];
  468. //
  469. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to remove this portfolio?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  470. //block代码块取代了delegate
  471. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  472. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Portfilio"];
  473. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  474. NSDictionary* cart_json = [RANetwork delete_portfoliolist:listid];
  475. dispatch_async(dispatch_get_main_queue(), ^{
  476. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  477. if([[cart_json valueForKey:@"result"] intValue]==2)
  478. {
  479. [self ReloadData];
  480. }
  481. else
  482. {
  483. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Portfolio" controller:self] ;
  484. }
  485. });
  486. });
  487. }];
  488. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  489. DebugLog(@"No");
  490. }];
  491. [alertControl addAction:actionOne];
  492. [alertControl addAction:alertthree];
  493. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  494. [self presentViewController:alertControl animated:YES completion:nil];
  495. }];
  496. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  497. NSString* create_user= [self.content_data[indexPath.row] valueForKey:@"create_user"];
  498. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  499. if([create_user isEqualToString:appDelegate.user])
  500. {
  501. return @[deleteRowAction];
  502. }
  503. return @[];
  504. }
  505. - (void)tableView:(UITableView *)tableView
  506. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  507. }
  508. - (void)reRefreshView {
  509. [self.table reloadData];
  510. }
  511. #pragma mark - RA_NOTIFICAITON
  512. -(void) refresh_ui
  513. {
  514. [self.table reloadData];
  515. }
  516. -(void) reload_data
  517. {
  518. self.offset = 0;
  519. [self.content_data removeAllObjects];
  520. [self.table reloadData];
  521. self.norefresh=true;
  522. [self loadpage];
  523. }
  524. @end