私はここから助けを受けています。iPhoneは別の場所からNSMutableArrayに追加しましたが、データを保持しません
私が行ったことは、BookmarksViewController.mというView Controller実装ファイルにNSMutableArrayを作成したことです。配列は適切に設定され、同じインプリメンテーションファイルに含まれているUITableViewに移入されます。
私の元の問題は、コマンドボタンでIBActionを実行することで、別のビューコントローラからその配列にオブジェクトを渡していたことです。配列に文字列(addObject)を渡すと、BookmarkViewControllerもナビゲーションスタックにプッシュされます。 View Controllerをナビゲーションスタックにロードすると、渡された文字列がはっきりと見えます。しかし、バック・ボタンを押してナビゲーション・スタックを離れすぎると、オブジェクトを追加したところに戻り、完全に消えてしまいます。
また、BookmarksViewController.mにボタンが付いているタブバーを使用して、そのボタンを押すと、新しい文字列が見えなくなります。私は何らかの理由で新しい文字列がナビゲーションパイルから一旦保持されていないことを考えていますが、一見してどのように配列に追加できるかを理解できません。
BookmarksViewController.h
#import <UIKit/UIKit.h>
#import "DissertationAppDelegate.h"
@interface BookmarksViewController : UITableViewController {
NSMutableArray *bookmarksArray;
DissertationAppDelegate *dissertationAppDelegate;
}
@property (nonatomic, retain) NSMutableArray *bookmarksArray;
@property (nonatomic, retain) DissertationAppDelegate *dissertationAppDelegate;
@end
BookmarksViewController.m
#import "BookmarksViewController.h"
@implementation BookmarksViewController
@synthesize bookmarksArray;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
bookmarksArray = [[NSMutableArray alloc]init];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [bookmarksArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [bookmarksArray objectAtIndex:indexPath.row];
return cell;
}
- (void)dealloc {
[bookmarksArray release];
[super dealloc];
}
Ch01GettingStarted.h
:ここがに関するコードであります
Ch01GettingStarted.m
#import "Ch01GettingStarted.h"
#import "BookmarksViewController.h"
#import "DissertationAppDelegate.h"
@implementation Ch01GettingStarted
@synthesize bookmarksViewController;
-(IBAction) pushChap01Bookmark:(id)sender{
[self.navigationController pushViewController:bookmarksViewController animated:YES];
bookmarksViewController.title = @"Bookmarks";
[bookmarksViewController.bookmarksArray addObject:@"NewString"];
NSLog(@"ADD ENTRY");
[bookmarksViewController.tableView reloadData];
NSLog(@"RELOAD TABLE");
}
- (void)dealloc {
[bookmarksViewController release];
[ScrollView release];
[super dealloc];
}
だから、BookmarksViewControllerでbookmarksArrayにオブジェクト "NEWSTRING" を追加してやっているように見えるものを。しかし、可能であれば、私はいつもそこにとどまりたいと思っています。
ありがとうございます。 Carl
こんにちはジョナ、お返事ありがとうございます。これは何が起きているのか、私がBookmarksViewControllerに戻ってくるたびに、ビューはロードされた元の設定に戻って設定されています。これは理にかなっています。その実装ファイルにviewDidLoadが必要ない場合、私の配列を何に入れることができますか?自分自身の - (void)配列などを作成することはできますか?ありがとうございました。 –
私はviewDidLoadからそれを移動したときにも、配列に文字列を追加しなくなりました。 –
私はUIViewControllerドキュメントを読んでいます。ありがとうございます。 –