我在NSObject類中有一個MutableArray我想將NSMutableArray傳遞給detailViewController然後我想在tableView(detailViewController)中顯示NSMutableArray。在這個項目中我有一個兩個視圖控制器,一個是firstViewcontroller和detailviewcontroller.the問題是數據不能從NSObject傳遞。給我一個想法,如果你想要更多信息請詢問。錯誤從NSObject傳遞NSMutableArray到ViewController
peripheralmanager.m
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
NSLog(@"didDiscoverPeriphera.peripheral: %@ rssi: %@, UUID:%@ advertisementData:%@", peripheral,RSSI,peripheral.UUID, [advertisementData description]);
targetPeripheral = peripheral;
peripheral.delegate = self;
// [[centralManager retrievePeripherals:NSArray arrayWithObject:(id)peripheral.UUID] ];
// rssilabel.text=[RSSI stringValue];
if (!peripheral.isConnected)
{
[centralManager connectPeripheral:peripheral options:nil];
}
// MeBleAppDelegate *appdelegate=(MeBleAppDelegate *)[[UIApplication sharedApplication]delegate];
MeBleDetailViewController *obj=[[MeBleDetailViewController alloc]init];
// MeBleDetailViewController *obj=[[appdelegate sharedappdelegate].navigationController objectATindex:MeBleDetailViewController];
obj.dataArray=self.mutableArray;
[self.mutableArray addObject:peripheral];
printf("New UUId,addin\r\n");
}
detailviewcontroller.m
- (void)viewDidLoad
{
//NSMutableArray *dataArray=[[NSMutableArray alloc]init];
[super viewDidLoad];
NSLog(@"%@",self.dataArray);
NSLog(@"%@",objCurrentDevice.mutableArray);
// PeripheralManager *peripheralmanager=[[PeripheralManager alloc]init];
self.label.text=[NSString stringWithFormat:@" %@ ",dataArray];
// Do any additional setup after loading the view.
// [self.dataArray addObject:objCurrentDevice.mutableArray];
appDelegate.arrDevices=dataArray;
appDelegate = [[UIApplication sharedApplication] delegate];
// write below line in any function in this file
// NSLog(@"%d",[appDelegate.arrDevices count]);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"Cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell==nil)
{
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text=[dataArray objectAtIndex:indexPath.row];
// PeripheralManager *objtemp=[[dataArray objectAtIndex:indexPath.row]deviceName];
NSLog(@"%@",objCurrentDevice.deviceName);
return cell;
}
錯誤消息
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x356c888f 0x37a6f259 0x3561d1d7 0x164db 0x33135c8b 0x331421e9 0x33142059 0x33141f3f 0x331417c1 0x33141503 0x33135aff 0x331357d5 0x331ae903 0x33228627 0x351e2933 0x3569ca33 0x3569c699 0x3569b26f 0x3561e4a5 0x3561e36d 0x372ba439 0x3312acd5 0x1500f 0x14fb4)
terminate called throwing an exception(lldb)
我想這樣image..Please輸出給一個idea..Please問我瞭解更多信息。
我想'[self.mutableArray ADDOBJECT:外圍]'可能會增加「無」 – BabyPanda
多少次你要問同樣的問題? – Abizern
@Abizern仍然錯誤我嘗試了很多方法。不要生氣很酷。 – prem