PDFListViewController.m 24 KB

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