cari

Rumah  >  Soal Jawab  >  teks badan

objective-c - 如何从tableViewcontroller中调用变量?

如题,继续小白学Ob-c,先谢各位大大!
想要把textfield中输入的变量存储在table中,附上代码:
在HWviewcontroller中的:
'''

import "HWViewController.h"

import "HWTableViewController.h"

@interface HWViewController ()
@property (nonatomic, strong) HWTableViewController *myTableViewController;

@property (strong, nonatomic) IBOutlet UISegmentedControl *mySegmentedControl;

@property (strong, nonatomic) IBOutlet UITextField *main;
@property (strong, nonatomic) IBOutlet UITextField *detail;
@property (strong, nonatomic) IBOutlet UIButton *addButton;
@property (strong, nonatomic) IBOutlet UIButton *showButton;
@property (strong, nonatomic) NSMutableDictionary *myItem;
@property (strong, nonatomic) NSString *combinedWord;
@end

@implementation HWViewController

}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{

NSLog(@"return button pressed");

[self.main resignFirstResponder];
[self.detail resignFirstResponder];
return YES;

}
-(IBAction)addPressed:(id)sender {
NSString *item=self.main.text;
NSString *detail=self.detail.text;
NSString *combine=[NSString stringWithFormat:@"%@%@",item,detail];
self.combinedWord=combine;
NSMutableArray *myWordArray = [[NSMutableArray alloc] init];
[myWordArray addObject:item];
[myWordArray addObject:detail];
[self.myItem setObject:myWordArray forKey:combine];

}
-(IBAction)showPressed:(id)sender {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.myTableViewController];

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Return"
                                                               style:UIBarButtonItemStyleDone target:self
                                                              action:@selector(dismissModalViewControllerAnimated:)];
[self.myTableViewController.navigationItem setLeftBarButtonItem:doneButton];


[self presentViewController:navController animated:YES completion:nil];

}

'''

然后tableviewcontroller的:
'''

import "HWTableViewController.h"

@interface HWTableViewController ()

@end

@implementation HWTableViewController

}

pragma mark - Table view data source

阿神阿神2768 hari yang lalu417

membalas semua(1)saya akan balas

  • 怪我咯

    怪我咯2017-04-22 09:02:41

    cell.textLabel.text = 这里想是self.main
    cell.detailTextLabel.text = 这里像是self.detail
    Ini jelas tidak mungkin, kerana tiada nilai ​​​​self.main, self.detail dan
    dalam paparan jadual anda. Sebenarnya terdapat beberapa cara untuk menyelesaikan masalah ini 记住,tableview有代理和数据源Terdapat cara yang lebih mudah untuk keluar dari papan kekunci


    balas
    0
  • Batalbalas