PDFListViewController.m 24 KB

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