我正在尝试构建一个Grouped Sectioned View。我想将数组设置为字典中的对象,但我遇到了空数组问题。 这是偶数吗?????有诀窍????
#import "RootViewController.h"
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Get the specific Node for this row.
Nodes *nodes = (Nodes *)[nodesMArray objectAtIndex:indexPath.row];
// Create the Details View Controller and initialize it.
nodesDetailView *viewController = [[nodesDetailView alloc] initWithStyle:UITableViewStyleGrouped ];
[[self navigationController] pushViewController:viewController animated:YES];
// Set the title of the view to the nodes name
viewController.title = [nodes computer_name];
//Information
//Network Data
viewController.ipaddress= [nodes ipaddress];
viewController.subnet_mask= [nodes subnet_mask];
viewController.gateway= [nodes gateway];
viewController.domain_name= [nodes domain_name];
}
#import "nodesDetailViewController. h
@interface nodesDetailView : UITableViewController{
//Network Data
NSString *ipaddress;
NSString *subnet_mask;
NSString *gateway;
NSString *domain_name;
//Grouped
NSMutableArray *Keys;
NSMutableDictionary *Contents;
}
@property (nonatomic, retain) NSMutableArray *Keys;
@property (nonatomic, retain) NSMutableDictionary *Contents;
@property (nonatomic, retain) NSString *ipaddress;
@property (nonatomic, retain) NSString *subnet_mask;
@property (nonatomic, retain) NSString *gateway;
@property (nonatomic, retain) NSString *domain_name;
@end
#import "nodesDetailViewController. m
@synthesize .......
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
NSMutableArray *keys = [[NSMutableArray alloc] init];
NSMutableDictionary *contents = [[NSMutableDictionary alloc] init];
NSString *network = @"Network Data";
NSString *product = @"Product Details";
//IS THIS POSSIBLE ??????? Because I get An Empty array
[contents setObject:[NSArray arrayWithObjects: ipaddress,subnet_mask, gateway, domain_name, nil] forKey:network];
return self;
}
先谢谢你。
答案 0 :(得分:0)
您添加到阵列的所有字符串尚未分配/初始化。这就是数组为空的原因。你不能只:NSString *emptyString;
然后去:[myArray addObject:emptyString];
。你的字符串都是空的。
答案 1 :(得分:0)
检查您从表格视图中传递的值。他们可能没有。我刚刚使用了这么多数据,我得到了正确的NSLog。
NSMutableDictionary *contents = [[NSMutableDictionary alloc] init];
NSString *my = @"kk";
NSString *my1 = @"polko";
[contents setObject:[NSArray arrayWithObjects: my1,my, nil] forKey:@"o"];
NSLog(@"%@" , contents);
答案 2 :(得分:0)
对于那些想知道的人:解决了问题我的代码很好。问题是: 它在错误的地方。
代码假设在 - (void)viewDidLoad而不在 - (id)initWithStyle:
我要感谢所有花时间去了解它的人。 我不知道为什么我把代码放在那里开始。
Thanx Again