我推送一個字符串從一個UIViewController到另一個到目前爲止,我成功做到了這一點,但是,當我將推送的字符串添加到NSMutableArray和NSLog數組總數時,它總是返回0這裏是我的代碼:我正在使用故事板,並且是否需要將第二個視圖引用到視圖中進行加載?推送數據從一個UIViewController到另一個
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_TableView setDelegate:self];
//[_TableView setDataSource:self];
_numberOfRows = [[NSMutableArray alloc]init];
}
-(void)pushName:(NSString*)contactName
{
//NSLog(@"Pushed name is: %@ ", contactName);
_contactName = contactName;
NSLog(@"Pushed name is: %@ ", _contactName);//<-- Returns the pushed string fine
[_numberOfRows addObject:contactName];
//[self.TableView reloadData];
NSLog(@"Number of names: %d ", [_numberOfRows count]);//<--Always returns a 0
}
不太確定爲什麼這不起作用。如果需要更多的代碼來澄清這個問題,那麼請不要問。
看看這裏http://stackoverflow.com/a/16142163/1328096 – jamil
@Undo不,這不是一個重複的問題我沒有通過一個NSMutableArray im傳遞一個單一的字符串我只想填充一個數組第二個UIViewController他們是完全不同的問題bro – Led
@one同樣的原則。任何傳遞數組的東西都可以傳遞一個字符串。只需查看答案並用'NSString'替換'NSMutableArray'即可。 – Undo