Iphone ';***-[u NSArrayM objectAtIndex:]:索引1超出范围[0..0]';
我得到了一个超出边界的索引错误。我试过改变数字,但没有成功! 任何帮助都将不胜感激。我一直在谷歌上搜索,在网上找到的所有解决方案都没有任何帮助。谢谢 mIphone ';***-[u NSArrayM objectAtIndex:]:索引1超出范围[0..0]';,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我得到了一个超出边界的索引错误。我试过改变数字,但没有成功! 任何帮助都将不胜感激。我一直在谷歌上搜索,在网上找到的所有解决方案都没有任何帮助。谢谢 m #导入“setingsviewcontroller.h” @接口设置可视控制器() @结束 @实现设置可视控制器 -(id)initWithStyle:(UITableViewStyle)样式 { self=[super initWithStyle:style]; 如果(自我){ //自定义初始化 } 回归自我; } -(无效)viewDidL
#导入“setingsviewcontroller.h”
@接口设置可视控制器()
@结束
@实现设置可视控制器
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//取消对下一行的注释以保留演示文稿之间的选择。
//self.clearselectiononviewwillappear=否;
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
//self.navigationItem.rightBarButtonItem=self.editButtonItem;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
//自定义表视图中的行数。
-(NSInteger)表视图:(UITableView*)表视图
节中的行数:(NSInteger)节{
返回2;
}
//自定义表格视图单元格的外观。
-(UITableView单元格*)表格视图:(UITableView*)表格视图
cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[NSBundle mainBundle]loadNibNamed:@“空”所有者:自选项:nil]objectAtIndex:0];
cell=[[NSBundle mainBundle]loadNibNamed:@“Cell1”所有者:自选项:nil]objectAtIndex:1];
}
返回单元;
}
-(NSString*)表格视图:(UITableView*)表格视图标题标题标题部分:(NSInteger)部分
{
NSString*节名;
道岔(区段)
{
案例0:
sectionName=NSLocalizedString(@“General”,@“General”);
打破
案例1:
sectionName=NSLocalizedString(@“myOtherSectionName”,@“myOtherSectionName”);
打破
// ...
违约:
sectionName=@;
打破
}
返回节名;
}
#pragma标记-表视图委托
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
//导航逻辑可能位于此处。创建并推送另一个视图控制器。
/*
*detailViewController=[[alloc]initWithNibName:@“bundle:nil];
// ...
//将选定对象传递给新的视图控制器。
[self.navigationController pushViewController:detailViewController动画:是];
*/
}
@结束
要加载我正在使用的自定义nib
创建NSObject类别类并在其中添加此代码
#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
并称之为
+ (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;
}
这会对你有所帮助。试试看。您和user2264008似乎在同一个类中(当然,数组索引超出范围是您遇到的最小问题)
+ (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)];
}