Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS新手-viewDidLoad_Ios_Objective C - Fatal编程技术网

iOS新手-viewDidLoad

iOS新手-viewDidLoad,ios,objective-c,Ios,Objective C,我正在浏览,在演示应用程序中遇到了一个错误 代码如下: #import "XYZToDoListViewController.h" #import "XYZToDoItem.h" @interface XYZToDoListViewController () @property NSMutableArray *toDoItems; -(void)viewDidLoad{ [super viewDidLoad]; self.toDoItems = [[NSMutableArra

我正在浏览,在演示应用程序中遇到了一个错误

代码如下:

#import "XYZToDoListViewController.h"
#import "XYZToDoItem.h"

@interface XYZToDoListViewController ()

@property NSMutableArray *toDoItems;
-(void)viewDidLoad{
    [super viewDidLoad];
    self.toDoItems = [[NSMutableArray alloc]init];
    [self loadInitialData];
}

@end

@implementation XYZToDoListViewController
-(void)loadInitialData{
    XYZToDoItem *item1 = [[XYZToDoItem alloc]init];
    item1.itemName = @"Buy Milk";
    [self.toDoItems addObject:item1];

    XYZToDoItem *item2 = [[XYZToDoItem alloc]init];
    item2.itemName = @"Go Shopping";
    [self.toDoItems addObject:item2];

    XYZToDoItem *item3 = [[XYZToDoItem alloc]init];
    item3.itemName = @"Wake Up";
    [self.toDoItems addObject:item3];
}
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{

}


- (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.
}

#pragma mark - Table view data source

- (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.toDoItems count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ListPrototypeCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
    cell.textLabel.text = toDoItem.itemName;
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

 */
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}
@end
在构建时,它出现了一个错误,表示它期望
viewDidLoad
之后。
我在谷歌上搜索了一下,看看是否能找到原因,但似乎无法找到。

您可能拥有以下属性:

@property NSMutableArray *toDoItems;
在实现文件(.m)或方法中:

-(void)viewDidLoad{
    ...
}
在头文件(.h)中


此外,您还需要一个
@实现
@接口
。也许您应该使用文件中的完整代码更新您的问题。

看起来您可能拥有以下属性:

@property NSMutableArray *toDoItems;
在实现文件(.m)或方法中:

-(void)viewDidLoad{
    ...
}
在头文件(.h)中


此外,您还需要一个
@实现
@接口
。也许你应该用文件中的完整代码更新你的问题。

把它放在你的.h文件中

 @interface className : Class that you inherit

 @property NSMutableArray *toDoItems;

 @end
当然,您需要将className替换为类的名称,将“继承的类”替换为超类,如NSObject、UIViewController、UIView或任何其他类

把这个放在你的.m文件里

@implementation className

-(void)viewDidLoad{
    [super viewDidLoad];
    self.toDoItems = [[NSMutableArray alloc]init];
    [self loadInitialData]; 
}

@end
这应该会有帮助


希望有帮助:)

将此文件放入.h文件中

 @interface className : Class that you inherit

 @property NSMutableArray *toDoItems;

 @end
当然,您需要将className替换为类的名称,将“继承的类”替换为超类,如NSObject、UIViewController、UIView或任何其他类

把这个放在你的.m文件里

@implementation className

-(void)viewDidLoad{
    [super viewDidLoad];
    self.toDoItems = [[NSMutableArray alloc]init];
    [self loadInitialData]; 
}

@end
这应该会有帮助


希望有帮助:)

下面的属性应该在.h文件中。因为在.h文件中我们需要声明方法,所以属性将声明应该在.h文件中的方法

 @property NSMutableArray *toDoItems;
下面是.m文件,因为在.m文件中我们需要定义方法

- (void)viewDidLoad
 {
[super viewDidLoad];

self.toDoItems = [[NSMutableArray alloc] init];
  [self loadInitialData];
    }

以下属性应位于.h文件中。因为在.h文件中我们需要声明方法,所以属性将声明应该在.h文件中的方法

 @property NSMutableArray *toDoItems;
下面是.m文件,因为在.m文件中我们需要定义方法

- (void)viewDidLoad
 {
[super viewDidLoad];

self.toDoItems = [[NSMutableArray alloc] init];
  [self loadInitialData];
    }

您是否将此代码放在头文件(*.h)中?您应该在
.m
文件中编写
-viewDidLoad
方法。它在.m文件中。您是否将此代码放在头文件(*.h)中?您应该在
.m
文件中编写
-viewDidLoad
方法。它在.m文件中file@downvoter,请在下一票前发表评论???@downvoter,请在下一票前发表评论??