- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在根据本教程 (http://bit.ly/NI9kQe) 构建一个应用程序,它使用自定义 Web API 连接到 Web 服务器。其中一项要求是检测是否点击了登录或注册按钮。这是使用在界面生成器中为按钮设置的“标签”完成的(注册按钮的标签为 1)。
代码块位于 btnLoginRegisterTapped 方法中,如下所示(错误发生在 -> NSString* command = (sender.tag==1)?@"register":@"login"; 行):
- (IBAction)btnLoginRegisterTapped:(id)sender {
//form fields validation
if (fldUserName.text.length < 4 || fldPassword.text.length < 4) {
// [UIAlertView error:@"Enter username and password over 4 chars each."];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!" message:@"Enter username and password over 4 chars each." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
// optional - add more buttons:
[alert addButtonWithTitle:@"Yes"];
[alert show];
return;
}
//salt the password
NSString* saltedPassword = [NSString stringWithFormat:@"%@%@", fldPassword.text, kSalt];
//prepare the hashed storage
NSString* hashedPassword = nil;
unsigned char hashedPasswordData[CC_SHA1_DIGEST_LENGTH];
//hash the pass
NSData *data = [saltedPassword dataUsingEncoding: NSUTF8StringEncoding];
if (CC_SHA1([data bytes], [data length], hashedPasswordData)) {
hashedPassword = [[NSString alloc] initWithBytes:hashedPasswordData length:sizeof(hashedPasswordData) encoding:NSASCIIStringEncoding];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!" message:@"Password cannot be reset!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
// optional - add more buttons:
[alert addButtonWithTitle:@"Yes"];
[alert show];
return;
}
//************ THIS IS WHERE THE ERROR OCCURS *****************//
//check whether it's a login or register
NSString* command = (sender.tag==1)?@"register":@"login";
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:
command, @"command",
fldUserName.text, @"username",
hashedPassword, @"password",
nil];
//make the call to the web API
[[API sharedInstance] commandWithParams:params
onCompletion:^(NSDictionary *json) {
//handle the response
//result returned
NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];
if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"IdUser"] intValue]>0) {
//success
[[API sharedInstance] setUser: res];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
//show message to the user
[[[UIAlertView alloc] initWithTitle:@"Logged in"
message:[NSString stringWithFormat:@"Welcome %@",[res objectForKey:@"username"] ]
delegate:nil
cancelButtonTitle:@"Close"
otherButtonTitles: nil] show];
} else {
//error
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!" message:@"Server down? Try Again" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
// optional - add more buttons:
[alert addButtonWithTitle:@"Yes"];
[alert show];
return;
}
}];
当我尝试构建项目(实际上是工作区)时出现错误:
在“_strong id”类型的对象上找不到属性“标签”
我正在使用 xcode 5.0 为 iOS7 部署。
谢谢,
最佳答案
属性语法不能与通用 id
类型的变量一起使用。
因此,要么用方法调用 [sender tag]
替换 sender.tag
,要么更好,在方法定义中使用 sender
参数的实际类型:
- (IBAction)btnLoginRegisterTapped:(UIButton *)sender { ... }
提示:在 Xcode 中使用“Control-Drag”创建 Action 时,使用“类型”字段中的弹出窗口选择发件人的实际类型。然后使用正确的参数类型创建操作方法。
关于ios - 在 'tag' 类型的对象上找不到属性 '_strong id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19641751/
这是我尝试在 IOS 中构建的第一个应用程序,但遇到了一些问题。虽然我在这里读过类似的帖子,但我找不到答案。我想在我的按钮点击上显示 popoverview Controller 。但无法做到。我在上
我提到了 this链接,因为我试图在 TableView 中对来自 Web 服务的数据进行排序。我的第一个问题是我们可以对可变数组中的数据进行排序吗?我在以下代码中遇到此编译器错误。 NSSortDe
我正在根据本教程 (http://bit.ly/NI9kQe) 构建一个应用程序,它使用自定义 Web API 连接到 Web 服务器。其中一项要求是检测是否点击了登录或注册按钮。这是使用在界面生成器
第一次使用Parse。不太确定这里发生了什么。感谢您的帮助。 MainTableViewController *controller = [[PFQueryTableViewController al
我将 tag 放在我的 UILabel 的 StoryBoard 属性检查器上,我的 ViewController.m 上有这段代码: for (id subview in [[self view]
我在这里尝试用功能 block 替换“@selector”。但是这样做会显示一条错误消息: 错误:发送 'void (^)(UIButton *__strong)' 到不兼容的参数 type 'SEL
我收到上述错误,但我不确定如何修复它,有人能告诉我为什么会收到此错误以便我修复它吗? 代码本身可以工作并将图像(文本层除外)绘制到屏幕上,所以我只想消除错误。我已经搜索过堆栈溢出并找到了“castin
我收到这个错误: incompatible pointer types assigning to NSError _strong from NSError _autoreleasing 这是我的头文件
我是一名优秀的程序员,十分优秀!