標籤:round pat 彈框 field loaddata tle return 名稱 .text
#pragma mark - 代理方法- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // 1.取得被點擊這行對應的模型 MJHero *hero = self.heros[indexPath.row]; // 彈框 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"資料展示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil]; // 設定對話方塊的類型 alert.alertViewStyle = UIAlertViewStylePlainTextInput; // 取得唯一的那個文字框,顯示英雄的名稱 [alert textFieldAtIndex:0].text = hero.name; [alert show]; // 綁定行號到alertView上 alert.tag = indexPath.row;}#pragma mark - alertView的代理方法/** * 點擊了alertView上面的按鈕就會調用這個方法 * * @param buttonIndex 按鈕的索引,從0開始 */- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 0) return; // 按鈕的索引肯定不是0 // 1.取得文字框最後的文字 NSString *name = [alertView textFieldAtIndex:0].text;// int row = alertView.tag;// NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];// UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];// cell.textLabel.text = name; // 2.修改模型資料 int row = alertView.tag; MJHero *hero = self.heros[row]; hero.name = name; // 3.告訴tableView重新載入模型資料 // reloadData : tableView會向資料來源重新請求資料 // 重新調用資料來源的相應方法取得資料 // 重新調用資料來源的tableView:numberOfRowsInSection:獲得行數 // 重新調用資料來源的tableView:cellForRowAtIndexPath:得知每一行顯示怎樣的cell // 全部重新整理// [self.tableView reloadData]; // 局部重新整理 NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0]; [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];}
IOS AlterView的使用(IOS8.0以前使用)