0
ApplicationViewController *a=[mesApplications objectAtIndex:3];

mesApplications 它是一个包含 ApplicationViewController 对象的数组,并希望我的UIViewConroller单元格显示每个 ApplicationViewController 包含的一些属性,当我使用它时:

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configuration des cellules
    ApplicationViewController *cellValue = [mesApplications objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue.name;
    NSLog(@"%@",cellValue);
    return cell;
}

日志是空的,我不知道解决方案?

4

1 回答 1

1

以下是基于您的描述的简短实现。它似乎表现正确。我希望你能找到缺少的东西。

问候

ViewController.nib 由一个 UITableView 组成,其中包括一个 UIButton(调用 addApplications)

视图控制器.h

#import <UIKit/UIKit.h>

@interface ApplicationViewController : UIViewController

@property   NSString*   name;

@end

@interface ViewController : UITableViewController

@property   ( nonatomic, retain )   NSArray*                mesApplications;

- ( IBAction ) addApplications: ( id ) sender;

@end

视图控制器.m

#import "ViewController.h"

@implementation ApplicationViewController

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mesApplications.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell*    cell            =   [ tableView dequeueReusableCellWithIdentifier: @"MyTableViewCell" ];

    if ( !cell )
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    ApplicationViewController*  pApp    =   [ self.mesApplications objectAtIndex: indexPath.row ];
    [ cell.detailTextLabel setText: pApp.name ];
    NSLog(@"%@", pApp);
    return cell;
}

- ( IBAction ) addApplications: ( id ) sender
{
    ApplicationViewController*  pApp1   =   [ ApplicationViewController new ];
    pApp1.name  =   @"app1";

    ApplicationViewController*  pApp2   =   [ ApplicationViewController new ];
    pApp2.name  =   @"app2";

    ApplicationViewController*  pApp3   =   [ ApplicationViewController new ];
    pApp3.name  =   @"app3";

    self.mesApplications =  [ NSArray arrayWithObjects: pApp1, pApp2, pApp3, nil];

    [self.tableView reloadData];
}

@end

和控制台转储

2013-03-11 13:38:17.132 kokio[10353:907] <ApplicationViewController: 0x1c535190>
2013-03-11 13:38:17.139 kokio[10353:907] <ApplicationViewController: 0x1c535260>
2013-03-11 13:38:17.142 kokio[10353:907] <ApplicationViewController: 0x1c535390>
于 2013-03-11T12:43:49.843 回答