Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Can';无法在UITableView中显示文本_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

Iphone Can';无法在UITableView中显示文本

Iphone Can';无法在UITableView中显示文本,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我有一个基于视图的应用程序,它只做一件事:在TableView中显示数组,但它不工作,我不知道为什么。这是密码 .h @interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{ NSArray *array; IBOutlet UITableView *table; } .m -(void)viewDidLoad{ [super viewDi

我有一个基于视图的应用程序,它只做一件事:在TableView中显示数组,但它不工作,我不知道为什么。这是密码

.h

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
    NSArray *array;
    IBOutlet UITableView *table;
}

.m

-(void)viewDidLoad{
[super viewDidLoad];
    array = [array initWithObjects:@"iPad", @"iTV", nil];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [array objectAtIndex:indexPath.row];

    return cell;
}
.h
@界面ViewController:UIViewController{
NSArray*阵列;
IBUITableView*表;
}
M
-(无效)viewDidLoad{
[超级视图下载];
array=[array initWithObjects:@“iPad”@“iTV”,nil];
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[数组计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
}
cell.textlab.text=[array objectAtIndex:indexath.row];
返回单元;
}

你知道为什么TableView不显示文本吗?谢谢大家

我假设你是在ARC下跑步

NSIndexPath没有“行”属性,请重试

NSInteger row = [indexPath indexAtPosition:1];
cell.textLabel.text = [array objectAtIndex:row];

我假设你是在ARC下跑步

NSIndexPath没有“行”属性,请重试

NSInteger row = [indexPath indexAtPosition:1];
cell.textLabel.text = [array objectAtIndex:row];
应该是

array = [NSArray initWithObjects:@"iPad", @"iTV", nil];
另外,请确保您按照前面提到的那样给arrayInit打电话

编辑: 文斯正确地指出,两者都应该如此

[[NSArray alloc] initWithObjects:@"iPad", @"iTV", nil];

取决于您是要保留还是自动释放它

应该是

array = [NSArray initWithObjects:@"iPad", @"iTV", nil];
另外,请确保您按照前面提到的那样给arrayInit打电话

编辑: 文斯正确地指出,两者都应该如此

[[NSArray alloc] initWithObjects:@"iPad", @"iTV", nil];


取决于您想保留还是自动释放它

调用的
arrayInit
方法在哪里?很抱歉,在viewDidLoad中调用了该方法。我要编辑它。调用的
arrayInit
方法在哪里?很抱歉,它在viewDidLoad中。我要编辑它。
nsindepath
在链接
UIKit
时有一个
属性。酷。每天学习新内容当您链接到
UIKit
时,XPath有一个
属性。酷。每天学习新的东西,不是吗?
[[NSArray alloc]initWithObjects:…]
[NSArray数组及其对象:…]?是的,你是对的,它应该是带有对象的数组。。。我没注意到,你这样做看起来不对。在viewDidLoad中初始化数组后,能否在其上设置断点并检查数组?忘记arrayInit方法吧,在viewDidLoad中初始化数组是可以的。只需在viewDidLoad方法中尝试[NSArray arrayWithObjects:@“iPad”,“iTV”,nil],看看这是否有帮助。现在一切正常。array=[[NSArray alloc]initWithObjects:@“iPad”,“iTV”,nil];很好。但是无论如何,TableView不会显示文本!将断点放在-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath?您的视图控制器正在加载吗?它不应该是
[[NSArray alloc]initWithObjects:…]
[NSArray数组及其对象:…]?是的,你是对的,它应该是带有对象的数组。。。我没注意到,你这样做看起来不对。在viewDidLoad中初始化数组后,能否在其上设置断点并检查数组?忘记arrayInit方法吧,在viewDidLoad中初始化数组是可以的。只需在viewDidLoad方法中尝试[NSArray arrayWithObjects:@“iPad”,“iTV”,nil],看看这是否有帮助。现在一切正常。array=[[NSArray alloc]initWithObjects:@“iPad”,“iTV”,nil];很好。但是无论如何,TableView不会显示文本!将断点放在-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath?您的视图控制器正在加载吗?