初めての投稿です。評判が 10 必要なため、画像をアップロードできません。XD でも問題ありません。
こんにちはみんな、まあ、2番目または子ビューコントローラーからテーブルビューのセルからlabel.textを最初または親ビューコントローラーに渡す必要があります。セルをプッシュして、ラベルにロードする文字列に戻ります最初のView Controllerから、ストーリーボードのセグエを使用しました。プロトコルとデリゲートを使用しましたが、機能しませんでした。別の質問では、回答または例が必要なものとは反対であるか、xcodeバージョンとは非常に異なる方法です。または、これを行うための最良の方法は何ですか?、写真では、次のView Controllerに移動するためのボタンを使用して、最初のView Controllerで必要なラベルテキストを選択します.Xcode 4.6とストーリーボードとARCも使用しています. &コードのいくつかの行は非推奨です。みんなを助けてください!! & どうもありがとう!!!、
ボリビアからのご挨拶!!! n_n'
コードは次のようになります。
@interface FirstViewController : UIViewController <SecondTableViewControllerDelegate>
@property (copy, nonatomic) NSString *displayText;
@property (weak, nonatomic) IBOutlet UILabel *displayLabel;
@property (strong, nonatomic)IBOutlet UIButton *Next;
@end
@interface FirstViewController ()
@end
@implementation FirstViewController
@synthesize Next;
-(void)viewDidLoad
{
[super viewDidLoad];
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FIRST_TIME"])
{
NSLog(@"ES PRIMERA VEZ");
[Next sendActionsForControlEvents:UIControlEventTouchUpInside];
}
else
{
NSLog(@"NO ES PRIMERA VEZ");
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.displayText)
{
self.displayLabel.text = self.displayText;
} else {
self.displayLabel.text = kDefaultDisplayText;
}
}
#pragma mark - Delegate methods
- (void)updateText:(NSString *)text {
self.displayText = text;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (![segue.identifier isEqualToString:@"toSecondTableview"]) {
return;
}
/*
SecondTableViewController *destinationController = segue.destinationViewController;
destinationController.delegate = self;
destinationController.editText = self.displayText;
*/
//-- if I pass data from the first view controller to the second right?
}
@end
in the second view
@protocol SecondTableViewControllerDelegate <NSObject>
@optional
- (void)updateText:(NSString *)text;
@end
@interface SecondTableViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) id<SecondTableViewControllerDelegate> delegate;
@property (copy, nonatomic) NSString *editText;
@property (weak, nonatomic) IBOutlet UITableView *myTable;
@interface SecondTableViewController ()
@end
@implementation SecondTableViewController
-(void)viewDidLoad
{
[super viewDidLoad];
[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"FIRST_TIME"];
//---how use the UItable Methods?, how use the protocol method?
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.myArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myArray";
myArrayCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *conjunto = [self.jogArray objectAtIndex:indexPath.row];
cell.myLabel.text = [conjunto objectForKey:@"prueba"];
return cell;
}
または、プロトコルデリゲートは他のView Controllerにある必要がありますか?、次のView Controllerの任意のセルのテキストをラベルに表示したいのですが、どうすればよいですか??