我有兩個視圖控制器:應用程序加載時看到的表視圖和選擇單元格時被按下的控制器。我有一個表視圖聲明中的變量,當它被push時,需要傳遞給另一個視圖控制器。變量給每個表格單元一個數字([objectAtIndex row] + 1),以使頂部的單元格爲1 。接下來是2.ect。我需要在視圖控制器中使用各種各樣的變量。我怎樣才能做到這一點?謝謝。當視圖控制器被按下時保存變量
這裏是第一視圖控制器代碼:
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [atableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"];
}
BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
//Variable that I need in the other view:
NSString *string = [NSString stringWithFormat:@"%d. %@",[indexPath row] + 1, p];
[[cell textLabel] setText:string];
return cell;
}
對不起@大衛,但林很新的IOS,我不知道是什麼KVC或志願是。你能否給我一個更具體的例子? – user1438042 2012-07-26 22:58:10