我想在viewDidLoad中使用appRecord.myName,
當我把它放在那裏它錯誤了,該appRecord是未申報的,如何聲明它?Objective-C語法初學者問題
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"pilotWay";
static NSString *PlaceholderCellIdentifier = @"PlaceholderCell";
int nodeCount = [self.entries count];
if (nodeCount == 0 && indexPath.row == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:PlaceholderCellIdentifier] autorelease];
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.detailTextLabel.text = @"load";
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (nodeCount > 0)
{
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
cell.textLabel.text = appRecord.myName;
cell.textLabel.text = appRecord.appName;
}
return cell;
}
我很困惑你想做什麼。它看起來像你的表中的每一行都有一個唯一的AppRecord對象。如果是這樣,在viewDidLoad方法中聲明一個AppRecord有什麼意義?當您的viewController類被加載時,該方法將被調用一次,而cellForRowAtIndexPath會在您的單元格被加載時被調用多次。 – kubi 2009-12-23 01:50:43
我們不要將Objective-C問題標記爲C.我們對C和C++有足夠的疑惑,因爲它沒有使用該標記拋出第三種語言。 – 2009-12-23 01:50:46
我只想在另一個從viewDidLoad調用的方法中使用myName的值(一個名爲AppRecord的不同類中聲明的NSString對象),如何? – 2009-12-23 02:12:35