Iphone UITableView不显示阵列中的数据

Iphone UITableView不显示阵列中的数据,iphone,ios,objective-c,uitableview,Iphone,Ios,Objective C,Uitableview,代码: 在h中: NSMutableArray *contentArray; 我正在声明我的数组 英寸 我正在我的视图中设置它。 我正在将行数设置为数组计数 没什么。但是如果我改为“[[cell textLabel]setText:@“Hello World.”];”,它就可以正常工作。尝试在init方法中初始化数组,或者在设置数组后在UITableView上调用重新加载数据 表中是否至少有3个空行?如果是,那么只需更改代码即可 NSString *tempString = [yo

代码:

在h中:

    NSMutableArray *contentArray;
我正在声明我的数组


英寸

我正在我的视图中设置它。 我正在将行数设置为数组计数



没什么。但是如果我改为“[[cell textLabel]setText:@“Hello World.”];”,它就可以正常工作。

尝试在init方法中初始化数组,或者在设置数组后在
UITableView
上调用
重新加载数据

表中是否至少有3个空行?如果是,那么只需更改代码即可

NSString *tempString = [your_array objectAtIndex:indexPath.row];
cell.textLabel.text = tempString; 
若您甚至并没有得到空字符串,那个么在.h文件中创建数组的属性。在.m中合成它(也在delloc函数中释放它),最后在viewDidLoad中加载

NSMutableArray tempContentArray = [[NSMutableArray alloc] arrayWithObjects:@"view", @"browse", @"create", nil];
self.contentArray=tempArray;
然后编写以下代码以获取单元格标题

NSString *tempString = [self.contentArray objectAtIndex:indexPath.row];
cell.textLabel.text = tempString; 

您在.m文件中的代码很好。编写property.h文件,合成并释放NSMutable array.m文件,这可能会对您有所帮助。

只需使用以下代码行即可 //使用对象初始化nsarray

-(void)viewDidLoad
{
NSArray *practice_ArrayForDisplayingEx=[NSArray alloc]initWithObjects:@"bhupi",@"bhupi",@"bhupi",@"bhupi",nil];

}


//then use in tableview.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";
   // UIButton *practice_takeTest_button;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]autorelease];
         }


    cell.textLabel.text =[practice_ArrayForDisplayingEx objectAtIndex:indexPath.row];
    cell.textLabel.font=[UIFont fontWithName:@"Arial" size:15];



    return cell;
}
确保在.h文件中包含UITableViewDelegate和UITableViewDataSourse prtocol


希望它能帮助您..

确保您的.h实现tableview委托和数据源。。。应该是这样的

 @interface myClass : UITableViewController <UITableViewDelegate, UITableViewDataSource>

谢谢我刚刚意识到,因为我没有使用导航控制器,所以从来没有调用viewDidLoad!我必须坚持我的初衷。再次感谢!
NSString *tempString = [self.contentArray objectAtIndex:indexPath.row];
cell.textLabel.text = tempString; 
-(void)viewDidLoad
{
NSArray *practice_ArrayForDisplayingEx=[NSArray alloc]initWithObjects:@"bhupi",@"bhupi",@"bhupi",@"bhupi",nil];

}


//then use in tableview.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";
   // UIButton *practice_takeTest_button;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]autorelease];
         }


    cell.textLabel.text =[practice_ArrayForDisplayingEx objectAtIndex:indexPath.row];
    cell.textLabel.font=[UIFont fontWithName:@"Arial" size:15];



    return cell;
}
 @interface myClass : UITableViewController <UITableViewDelegate, UITableViewDataSource>
 [self.tableView setDelegate:self];
 [self.tableView setDataSource:self];