思路:
1、根據數組的索引和indexpath的row聯繫起來
2、現在didSelectedRowAtIndexPath中彈出UIAlertView和相關信息,然後在UIAlertView協議的clickedButtonAtIndex中將alert的數據傳遞給數據源,然後通過刷新,即可形成信息的改。
3、右側的箭頭:cell setAccessoryType:
4、改完數據以後要更新,有全部更新和更具選中行部分更新
1、1選中行返回選中行的indexpath tableview indexPathForSelectedRow
開發中常見的隱藏問題:
如果寫了cell代碼優化,並且需求是每行根據實際的數目來顯示,那麼當超出屏幕範圍的時候,從緩衝池中取出單元行時,會顯示出一整行的內容,卻不是實際的個數。
所以要寫判斷
如若需要將狀態欄隱藏,最好使用代碼實現
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
- (BOOL)preferstatusBarHidden
{
return YES;
}
UIAlertView中的按鈕和文本行可以利用index來指向
表格優化: 數字11的含義
單元格內容方法
1、標示符統一,使用static的目的可以保證表格標示符永遠只有一個
static NSString* cellIdentifier = @"myCell";
2、首先在緩衝池中找名爲“myCell”的單元格對象
UITableViewCell* cell = [tableview dequeueReusableCellWithIdentifier:cellIdentifier];
3、如果沒有找到,實例化一個新的cell
if (cell == nil)
{
cell = [[UITableCell alloc] initWithStyle:UITableViewCellStyleDefautl reuseIdentifier:cellIdentifier];
}
Navigation Controller和TableView相結合
在級聯中,利用上下級視圖,在prepareForSegue中,獲取下級的viewController然後利用set方法傳遞數據給下級的viewController。再在下級視圖中顯示
代碼塊功能提高複用性
//TODO:
<#xxxx#>代碼table顯示
表格移動行的方法,只要實現了- (void)tableView:moveRowAtIndexPaht:toIndexPath即可
實際是先刪除了原來位置的數據,進行了記錄,然後在目標位置再還原
其實的目標位置之所以不用加一,是因爲其實在刪除原來位置的同時,總數已經減1了,插入後的總數其實還是沒有變化
static NSString *CellIdentifier = @"bookCell";
// 2. 從緩存池查找是否有可用的表格行對象
BookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// 3. 如果沒有找到可重用單元格對象,實例化新的單元格
if (cell == nil) {
NSLog(@"實例化單元格對象");
cell = [[BookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
IOS6之後:
static NSString *CellIdentifier = @"bookCell";
// 2. 從緩存池查找是否有可用的表格行對象
BookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
前提已經在storyboard中建立了cell或者註冊了xib文件,使用了自定義單元格
注意xib中的identifire
// 注意:以下幾句註冊XIB的代碼,一定要在viewDidLoad中!
// 註冊XIB文件
UINib *nib = [UINib nibWithNibName:@"BookCell" bundle:[NSBundle mainBundle]];
// 獲得根視圖,並且轉換成TableView
UITableView *tableView = (UITableView *)self.view;
// 爲tableView註冊xib
[tableView registerNib:nib forCellReuseIdentifier:@"bookCell"];
重點:表格優化,根據系統的版本。
//新增表格數據
[tableViewinsertRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationTop];
//刪除表格數據
[tableViewdeleteRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationRight];
//局部刷新指定的行
[tableViewreloadRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationMiddle];
//刷新全部表格數據,如果能夠準確確定被修改的數據行,就不要用此方法
[tableViewreloadData];不支持動畫,僅在我們不知道哪個位置的數據被改了才使用
- (void)tableView:commitEditingStyle:forRowAtIndexPath:
- (UITableViewCellEditingStyle)tableView:editingStyleForRowAtIndexPath:
UITextView 多行文本。支持編輯,數據檢測
2、;