1

'これをまったく機能させることはできません! 画面全体を占める TableView の単純なクラスがありましたが、それを半分にスライスすることにしたので、テーブルは画面の上半分だけを占めました。これは私のコードです:

これは TableSplitViewController.h です

 @interface TableSplitViewController : UIViewController
{
    ChildrenTableViewController *firstController;
    IBOutlet UITableView *firstTable;

}

これは TableSplitViewController.m です。

- (void)viewDidLoad
  { 
[super viewDidLoad];
if (firstController == nil) {
    firstController = [[ChildrenTableViewController alloc] init];
}
    [firstTable setDataSource:firstController];
    [firstTable setDelegate:firstController];
    firstController.view = firstController.tableView;

 }

これは ChildrenTableViewController.h です。

@interface ChildrenTableViewController : UITableViewController

@property (nonatomic, strong) NSMutableArray *childname;

@end

これは ChildrenTableViewController.m です。

    @implementation ChildrenTableViewController

         @synthesize childname;



  - (id)initWithStyle:(UITableViewStyle)style
  {
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
 }

  - (void)viewDidLoad
    {
     [super viewDidLoad];
     self.childname = [[NSMutableArray alloc]
                      initWithObjects:@"Oliver",
                      @"Stuart",
                      @"Ross",
                      @"Alex", nil];
}

   -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
   {
      if ([[segue identifier] isEqualToString:@"ShowChildrenDetails"]) {
            ChildrenDetailViewController *detailViewController = [segue     destinationViewController];

          NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

          detailViewController.childrenDetailModel = [[NSArray alloc]
                                                    initWithObjects: [self.childname  objectAtIndex:[myIndexPath row]], nil];
     }
  }


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



  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
   {
    // Return the number of sections.
    return 1;
  } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
   {

      // Return the number of rows in the section.
      return [self.childname count];
  }

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

      ChildrenTableViewCell * cell = [tableView   dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
          cell = [[ChildrenTableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
       }
      // Configure the cell..
      cell.childname.text = [self.childname objectAtIndex:[indexPath row]];


    return cell;
}

これは ChildrenTableViewCell.h です。

@interface ChildrenTableViewCell : UITableViewCell
@property (nonatomic, strong) IBOutlet UILabel *childname;

@end

これは ChildrenTableViewCell.m です。

@implementation ChildrenTableViewCell

@synthesize childname;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

絵コンテレイアウトの印刷画面です。子の名前のラベルを付けたので、名前を出力する必要があります。

スクリーンショット 1

これは実行中の印刷画面です。奇妙に 4 つの行があり、それらを選択できますが、ラベルが印刷されていません。

![スクリーンショット 2][2]

提供できるすべてのヘルプとサポートに感謝します。ありがとう :)

[2] http://puu.sh/1USzX/512ede1328

IOSDEV のおかげで、なぜそれが行われていたのかを突き止めることができました。

cell.childname.text = [self.childname objectAtIndex:[indexPath row]];
NSLog(@"%@",[self.childname objectAtIndex:[indexPath row]]);
NSLog(@"%@",cell.childname.text);

これは私が自分のコードに入れたものです。

そして、これは私が得たものです:

2013-01-30 15:33:52.465 TableViewStory[17509:907] Oliver
2013-01-30 15:33:52.467 TableViewStory[17509:907] (null)
2013-01-30 15:33:52.470 TableViewStory[17509:907] Stuart
2013-01-30 15:33:52.472 TableViewStory[17509:907] (null)
2013-01-30 15:33:52.473 TableViewStory[17509:907] Ross
2013-01-30 15:33:52.474 TableViewStory[17509:907] (null)
2013-01-30 15:33:52.476 TableViewStory[17509:907] Alex
2013-01-30 15:33:52.477 TableViewStory[17509:907] (null)

cell.childname.text が null に等しいことがわかるように、これがテキストが表示されない理由です。

4

1 に答える 1

0

TableSplitViewController.m で initWithStyle を使用する必要があります。

firstController = [[ChildrenTableViewController alloc] initWithStyle:UITableViewStyleGrouped]; 

何らかの理由で、tableView の初期化に使用しなかったときに、同様の問題がいくつかありました。

于 2013-01-30T14:08:33.610 に答える