Iphone objective-C语法初学者问题
我想在viewDidLoad中使用appRecord.myName,Iphone objective-C语法初学者问题,iphone,objective-c,Iphone,Objective C,我想在viewDidLoad中使用appRecord.myName, 当我把它放在那里时,发现appRecord未声明,如何声明它 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"pilotWay"; static NSString *Placeh
当我把它放在那里时,发现appRecord未声明,如何声明它
- (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
(=
这样做)。也许您需要强制转换它:(AppRecord*)[self.entries objectAtIndex:indexPath.row]
。无论您做什么,要检查是否存在appRecord
,请尝试以下操作并运行:
NSLog(@"appRecord: %@", appRecord);
您应该获得对象的描述
appRecord
,如果它存在,还应该有一个内存地址。请告诉我这些是否有用,或者您是否需要进一步解释。您是否在该文件的顶部有#import“AppRecord.h”
?该类没有在任何地方声明,我想这就是他的问题所在。感谢您的回复!appRecord是在一个方法中声明的,该方法没有从viewDidLoad调用appRecord,因此appRecord仍然是未定义的。声明了类,类中的一切工作正常,但是如果我想在viewDidLoad中使用appRecord.myName用于另一个目的,appRecord还没有定义,如何定义它?是的,类中的一切工作正常,但是,如果我想在viewDidLoad中使用appRecord.myName用于另一个目的,appRecord还没有定义,那么如何定义它呢?我不知道您想做什么。看起来表中的每一行都有一个唯一的AppRecord对象。如果是这样,在viewDidLoad方法中声明AppRecord有什么意义?当你的VIEW控制器类被加载时,这个方法将被调用一次,而CyfFurWurnRexPosix在你的单元格加载时被调用多次。让我们不要把Objto-C问题标记为C。我们对C和C++有足够的混淆,而不是使用那个标签抛出第三种语言。我只想使用MyNAME的值。(在另一个名为AppRecord的类中声明的NSString对象)在另一个从viewDidLoad调用的方法中,如何?