我有一個分段的tableView加載所有部分的所有單元格中的所有數據。 每個單元格中都有一個textField。UITableView單元格/數據消失
桌面視圖並不完全適合iPad屏幕,我無法訪問所有不可見的單元格以讀取/保存數據。當我在「textField」中進行更改時,然後向上滾動,向下滾動,所有更改都消失。
我需要加載所有單元格,甚至不可見一次,以便能夠訪問它們。
對不起,我剛剛在幾天前開始使用表格...... 我認爲這個問題與可重用單元格有關,但不知道如何解決它。
尋求你的幫助,請。
初始化:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400, 30)] ;
textField.enabled = NO;
cell.accessoryView = textField;
[textField release];
}
UITextField *textField = (UITextField*)cell.accessoryView;
if(indexPath.section == 0)
cell.textLabel.text = [idenInfo objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
cell.textLabel.text = [prodInfo objectAtIndex:indexPath.row];
else if (indexPath.section == 2)
cell.textLabel.text = [visInfo objectAtIndex:indexPath.row];
if(indexPath.section == 0)
textField.text = [idenInfoRez objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
textField.text = [prodInfoRez objectAtIndex:indexPath.row];
else if (indexPath.section == 2)
textField.text = [visInfoRez objectAtIndex:indexPath.row];
textField = nil;
return cell;
}
我如何知道哪個單元格(indexPath)的textField稱爲事件? 所以我實際上可以修改相應的數據源? – Razp 2011-04-13 11:58:49
看看UITableViewDataSource協議方法。你會發現你需要實現的方法,以便知道表中的用戶操作修改了哪個indexPath。我也會做一些閱讀。 iOS應用程序編程指南介紹了MVC設計模式。表格視圖控制器編程指南是表格的最佳開始。 – XJones 2011-04-13 20:44:33