我一直在尝试从plist文件读取数据。这就是它的结构
|term|detail(string)|
Run Code Online (Sandbox Code Playgroud)
我的财产:
@property (nonatomic, strong) NSDictionary *terms;
@property (nonatomic, strong) NSArray *termKeys;//this is just a array to keep track
@property (nonatomic, strong) NSString *detail;
Run Code Online (Sandbox Code Playgroud)
这是我访问cellForRowAtIndexPath中的详细信息的方式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSString *currentTermsName = [termKeys objectAtIndex :[indexPath row]];
[[cell textLabel] setText:currentTermsName];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
detail = [terms objectForKey:[termKeys objectAtIndex:indexPath.row]];
NSLog(@" bombs %@",terms[@"Bomb Threats"]);
return cell;
}
Run Code Online (Sandbox Code Playgroud)
鉴于didload我有
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myfile = [[NSBundle mainBundle]
pathForResource:@"terms" ofType:@"plist"];
terms = [[NSDictionary …Run Code Online (Sandbox Code Playgroud) 我怎样才能简化if语句
!(!a || b)?
为什么它实际上可能?
UPD:
抱歉.不优化,但简化:)
如何获取使用 JSON 解码实现的 php 字符串:
[
{
"rank": 5,
"day": 1
},
{
"rank": 4,
"day": 5
}
]
Run Code Online (Sandbox Code Playgroud)
进入这个 php 多维数组:
{
[
0
]=>array(2){
[
"rank"
]=>int(5)[
"day"
]=>int(1)
}[
1
]=>array(2){
[
"rank"
]=>int(4)[
"day"
]=>int(5)
}
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用 $multiArray[$x]['day'] 访问它。例如 echo $multiArray[0]['day']; 产生 1 并 echo $multiArray[1]['day']; 产生 5.
我尝试过 json_decode 但无法让它工作。
我一直试图找出为什么这个错误发生了一段时间我把tableview放在视图控制器中.将tableview委托和数据源设置为view controller.我已经实现了委托和数据源协议.
我在新项目中做了近4次相同的场景,它工作得很好.当我试图在我当前的项目中实现这个场景时,我看到了这个错误.
如果我删除设置表视图的委托,那么一切都很顺利.
它是在返回细胞后发生的.
可能是什么原因?我无法理解它.我也没有使用数组.