I have a simple TableView, when the cell is selected I want that the content is passed to several fields in a detail view so that they can be changed and saved again in the table.
我的代码没有问题,没有错误,并且在调试时完美地设置了所有变量,但我的字段仍然为空。我尝试使用数组,尝试使用字符串,但无法治愈。
我正在使用来自 Java 的 Objective-C 迈出第一步,有人可以吗?
这是我的代码:
在我的 TableViewController.m 中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
SNMGps *selectedCell = [arrayOfCell objectAtIndex:indexPath.row];
NSLog(@"%d - '%@ - '%@'- '%@'- '%@'", selectedCell.gpsID, selectedCell.name,selectedCell.userName,selectedCell.psw, selectedCell.notes);
SNMAddViewController *field = [[SNMAddViewController alloc]init];
//[field setGpsID1:selectedCell.gpsID];
[field setName1:selectedCell.name];
[field setUserName1:selectedCell.userName];
[field setPsw1:selectedCell.psw];
[field setNotes1:selectedCell.notes];
[field setFields];
}
NSLOG 显示完美的数据。
在我的 DetailViewController.h
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "SNMGps.h"
@interface SNMAddViewController : UIViewController
@property(strong, nonatomic) NSString *name1;
@property(strong, nonatomic) NSString *userName1;
@property(strong, nonatomic) NSString *psw1;
@property(strong, nonatomic) NSString *notes1;
//@property(strong, nonatomic) NSString *gpsID1;
@property (strong, nonatomic) IBOutlet UITextField *nameText;
@property (strong, nonatomic) IBOutlet UITextField *userNameText;
@property (strong, nonatomic) IBOutlet UITextField *pswText;
@property (strong, nonatomic) IBOutlet UITextField *notesText;
- (IBAction)saveEntry:(id)sender;
- (void) setFields;
@end
在我的 DetailViewController.m
#import "SNMAddViewController.h"
@interface SNMAddViewController ()
@end
@implementation SNMAddViewController
//@synthesize nameText, userNameText, pswText, notesText, g;
NSMutableArray *arrayOfCell;
NSString *dbPathString;
sqlite3 *gpsDB;
@synthesize name1, userName1, psw1, notes1;
@synthesize nameText, userNameText, pswText, notesText;
- (void) setFields
{
nameText.text = [NSString stringWithFormat:@"%@",name1];
userNameText.text = [NSString stringWithFormat:@"%@",userName1];
pswText.text = [NSString stringWithFormat:@"%@",psw1];
notesText.text = [NSString stringWithFormat:@"%@",notes1];
}
当我调试变量 name1、userName1 等时设置为正确的数据,但字段 nameText.text 仍然为零。