-3

UITableView の区切り線をカスタマイズする必要があり、そのためには、次のように cellForRowAtIndexPath メソッド内のリソース (png ファイル) にアクセスする必要があります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

// Some code here

myCustomSeparator.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"separator.png"]];

// Code ...

}

問題は、このメソッド内のリソースにアクセスするのは良い習慣ではないと聞いたことです。本当ですか?

4

1 に答える 1

1

とにかく、あなたが望むものを達成するための標準的な方法は、以下のコードです:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   // Some code here

   UIImageView *imagView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seprater.png"]];
   imgView.frame = CGRectMake(0, 100, 320, 1); // you can play with numbers here
   [customCell.contentView addSubview:imageView];

   // Code ...

   return customCell;
}
于 2013-08-08T21:44:54.740 に答える