我有这个错误,当我试图将myite中的tableView:didSelectRowAtIndexPath:方法中的uitextfeild值传递给我的nsobject类但是当我单击我编码的uitableviewcell来传递uitextfield值时,我收到了错误列在下面。
// DBAccess.h
@interface DBAccess : NSObject {
NSString *receiveCodeText;
}
@property (nonatomic, retain) IBOutlet NSString *receiveCodeText;
- (NSMutableArray *) getAllMakes;
- (void) setPassCode:(NSString *)theCode;
// DBAccess.m
//...
//Need to set my string here..
- (void)setPassCode:(NSString *)theCode{
receiveCodeText = theCode;
}
//...
- (NSMutableArray *)getAllMakes{
//...
const char *value = [receiveCodeText cStringUsingEncoding:NSUTF8StringEncoding]; //reciveCodeText is set in RootViewController and passed to value here
[receiveCodeText release];
sqlite3_bind_text(statement, 1, value, -1, SQLITE_TRANSIENT);
//....
}
// viewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
searchTableViewController *searchTable = [[searchTableViewController alloc] initWithNibName:@"searchTableViewController" bundle:nil];
switch (indexPath.row) {
case 1: {
searchTable.editedFieldName = @"Make";
//Pass code number over to DBAccess class
[DBAccess setPassCode:codeText.text];
} break;
case 2: {
searchTable.editedFieldName = @"Mod";
} break;
case 3: {
searchTable.editedFieldName = @"Method";
} break;
}
[self.navigationController pushViewController:searchTable animated:YES];
[searchTable release];
}
这是我得到的错误。
> 2011-06-13 13:05:33.433
> Code1.6[1318:207] +[DBAccess
> setPassCode:]: unrecognized selector
> sent to class 0x51e8 2011-06-13
> 13:05:33.477 Code1.6[1318:207] ***
> Terminating app due to uncaught
> exception
> 'NSInvalidArgumentException', reason:
> '+[DBAccess setPassCode:]:
> unrecognized selector sent to class
> 0x51e8'
> *** Call stack at first throw: ( 0 CoreFoundation
> 0x00e45be9 __exceptionPreprocess + 185
> 1 libobjc.A.dylib
> 0x00f9a5c2 objc_exception_throw + 47
> 2 CoreFoundation
> 0x00e477bb +[NSObject(NSObject)
> doesNotRecognizeSelector:] + 187 3
> CoreFoundation
> 0x00db7366 ___forwarding___ + 966 4
> CoreFoundation
> 0x00db6f22 _CF_forwarding_prep_0 + 50
> 5 Code1.6
> 0x000028ff -[RootViewController
> tableView:didSelectRowAtIndexPath:] +
> 253 6 UIKit
> 0x00331794 -[UITableView
> _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
> + 1140 7 UIKit 0x00327d50 -[UITableView
> _userSelectRowAtPendingSelectionIndexPath:]
> + 219 8 Foundation 0x0003a7f6 __NSFireDelayedPerform +
> 441 9 CoreFoundation
> 0x00e26fe3
> __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
> + 19 10 CoreFoundation 0x00e28594 __CFRunLoopDoTimer + 1220
> 11 CoreFoundation
> 0x00d84cc9 __CFRunLoopRun + 1817 12
> CoreFoundation
> 0x00d84240 CFRunLoopRunSpecific + 208
> 13 CoreFoundation
> 0x00d84161 CFRunLoopRunInMode + 97 14
> GraphicsServices
> 0x016e7268 GSEventRunModal + 217 15
> GraphicsServices
> 0x016e732d GSEventRun + 115 16 UIKit
> 0x002ca42e UIApplicationMain + 1160
> 17 Code1.6
> 0x0000230c main + 102 18 Code1.6
> 0x0000229d start + 53 ) terminate
> called after throwing an instance of
> 'NSException'
答案 0 :(得分:4)
setPassCode似乎是一个类实例方法而不是静态方法,但是你试图以静态方法的形式访问它,你必须声明yur方法,以便它是静态的
+(void)setPassCode....
您的程序崩溃是因为您在类本身而不是类的实例上调用方法。 希望这有帮助