cell = [[[NSBundle mainBundle] loadNibNamed:@"Empty" owner:self options:nil] objectAtIndex:0];
cell = [[[NSBundle mainBundle] loadNibNamed:@"Cell1" owner:self options:nil] objectAtIndex:1];
我得到超出边界错误的索引。我试图改变数字,但没有运气! 任何帮助将不胜感激。我一直在谷歌搜索,在网上找到的所有解决方案都没有帮助。感谢。
的.m
#import "SettingsViewController.h"
@interface SettingsViewController ()
@end
@implementation SettingsViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return 2;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"Empty" owner:self options:nil] objectAtIndex:0];
cell = [[[NSBundle mainBundle] loadNibNamed:@"Cell1" owner:self options:nil] objectAtIndex:1];
}
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionName;
switch (section)
{
case 0:
sectionName = NSLocalizedString(@"General", @"General");
break;
case 1:
sectionName = NSLocalizedString(@"myOtherSectionName", @"myOtherSectionName");
break;
// ...
default:
sectionName = @"";
break;
}
return sectionName;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end
答案 0 :(得分:0)
要加载我正在使用的自定义笔尖,
制作NSObject类别类并在其中添加此代码。
+ (id)loadNibNamed:(NSString *)NibName {
NSObject *cl = nil;
if (NSClassFromString(NibName) != nil) {
NSArray *arr = [[NSBundle mainBundle] loadNibNamed:NibName owner:self options:nil];
for (id cls in arr) {
if([cls isKindOfClass:NSClassFromString(NibName)])
{
cl = cls;
break;
}
}
}
return cl;
}
并称之为,
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = (UITableViewCell *)[[class class] loadNibNamed:NSStringFromClass(class)];
}
它会帮助你。