我正在尝试构建一个登录应用程序,但每次我尝试添加用户的姓名和公司时,应用程序都会崩溃。我相信这是当我试图从文本字段中获取文本并将其添加到我的可变数组中时,但我不知道该错误是否与表格视图或其他类似内容有关。我之前已经发布了一个类似错误的问题,但现在我实际上在模拟器中出现了表格视图。
目前,两个表视图都设置为做同样的事情。他们的数据源和委托连接到文件的所有者,当我在可变数组中有测试数据时,他们会工作。
任何帮助将不胜感激!
错误:
2013-06-03 13:49:03.446 SignIn[12225:11303] -[__NSArrayI addObject:]:无法识别的选择器发送到实例 0x75aa4b0 2013-06-03 13:49:03.447 SignIn[12225:11303] * 由于应用程序终止uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x75aa4b0' * First throw call stack: (0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2b96 0x10e3705 0x172c0 0x17258 0xd8021 0xd857f 0xd76e8 0x46cef 0x46f02 0x24d4a 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x202d 0x1f55)libc++abi.dylib:终止调用抛出异常(lldb)
相关代码(用**包围的add方法):
。H:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITextField *name;
@property (weak, nonatomic) IBOutlet UITextField *company;
- (IBAction)add:(id)sender;
@end
米:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
{
NSMutableArray *currentNames;
NSMutableArray *currentCompanies;
NSMutableArray *names;
NSMutableArray *companies;
}
@synthesize name, company;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [currentNames count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [currentNames objectAtIndex:indexPath.row];
return cell;
}
**- (IBAction)add:(id)sender {
BOOL exists = [names containsObject:name.text];
if(exists == FALSE){
[currentNames addObject:[name text]];
[currentCompanies addObject:[company text]];
[names addObject:[name text]];
[companies addObject:[company text]];
}
else{
[currentNames addObject:[name text]];
[currentCompanies addObject:[company text]];
}
name.text=@"";
company.text=@"";
}**
@end