【发布时间】:2016-03-11 04:54:31
【问题描述】:
我的应用程序使用存储在 dataModel 类中的 deviceToken 类。设备令牌通过各种AFNetworking commands 在整个应用程序中使用。
//Notice the syntax for the deviceToken class in this NSDictionary
NSDictionary *params = @{@"cmd":@"join",
@"token":[_dataModel deviceToken],
下面是通过NSMutableDictionary 使用[_dataModel deviceToken] 类的另一种方式。
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command",
[_dataModel deviceToken], @"token", nil ];
问题是我的应用程序使用两种不同的 API,我想通过 j 子将 [_dataModel deviceToken] 类传递给新字典。此词典当前在 UILabel 中显示用户的用户名,称为 caption。
//This message organizes photos, and shows the users username on them
-(id)initWithIndex:(int)i andData:(NSDictionary*)data
{
self = [super init];
if (self !=nil)
{
//add the photo caption
UILabel* caption = [[UILabel alloc] initWithFrame:CGRectMake(0, kThumbSide-32, kThumbSide, 32)];
caption.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"username"]];
[self addSubview: caption];
}
我想用设备令牌格式化UILabel,即caption,如上所示,它当前显示用户名。问题是当我尝试像这样在标题标签中显示设备令牌时,我遇到了编译器问题。正确的语法是什么?
caption.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"token"],[_dataModel deviceToken]];
【问题讨论】:
-
我想你忘了在 stringWithFormat
caption.text = [NSString stringWithFormat:@"%@%@",[data objectForKey:@"token"],[_dataModel deviceToken]];中添加一个 % 符号
标签: ios json afnetworking