在增加主计长时,我宣布如下文所示为国家安保局。
NSString *nameOfAlarm; // in .h
@property (nonatomic, retain) NSString *nameOfAlarm; //in .h
@synthesize nameOfAlarm; //in .m
在GisoDidLoad,我开始说,它如下:
nameOfAlarm = [[NSString alloc] initWithString:@"Alarm"];//In ViewDidLoad
之后 我正在做如下事情:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", indexPath.section, indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
// Configure the cell...
if (indexPath.section == 0) {
UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = mySwitch;
[(UISwitch *)cell.accessoryView setOn:YES]; // Or NO, obviously!
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(mySelector:)
forControlEvents:UIControlEventValueChanged];
NSString *cellValue = [NSString stringWithFormat:@"Enable Alarm"];
cell.textLabel.text = cellValue;
//return cell;
}
if (indexPath.section == 1) {
if (indexPath.row == 0) {
NSString *cellValue = [NSString stringWithFormat:@"Name "];
cell.textLabel.text = cellValue;
NSString *cellValue2 = [NSString stringWithFormat:@"%@",(NSString*)nameOfAlarm];
cell.detailTextLabel.text = cellValue2;
}
因此,我正在对GisWillAppear的表格进行重载。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"ViewWillAppear, The name is %@",nameOfAlarm);
[self.tableView reloadData];
}
我书写了其他控制人员正在使用的方法。
- (void) processName: (NSString *)n{
nameOfAlarm = (NSString *)n;
NSLog(@"Name is %@",nameOfAlarm);
}
现在,当我点上了0个浏览指数时,它就只能指名控制器,而名称控制器的h是
#import <UIKit/UIKit.h>
@protocol ProcessNameDelegate <NSObject>
@required
- (void) processName: (NSString *)n;
@end
@interface Name : UITableViewController <UITextFieldDelegate>{
id <ProcessNameDelegate> delegate;
UITextField *name_textField;
}
@property (retain) id delegate;
@property (nonatomic, retain) UITextField *name_textField;
- (void)pressComplete;
@end
在回到以前的控制器时,将采用以下方法:
- (void)pressComplete {
NSString *name = (NSString *)name_textField.text;
[[self delegate] processName:name];
}
This will set value to nameOfAlarm Everything is fine, but when I do reload then this is not showing in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
如果我确实使用名称的话,它就显示出以下一些情况: OfAlarm in cell Value or甚至是在做国家后勤记录仪时,
<_UIStretchableImage: 0x14db10> //the first time in nameOfAlarm,
第二次 如果我能以名望控制器并做的话,那么将印制如下:
<UILabel: 0x1cd6c0; frame = (13 0; 25 27); text = ON ; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1d75f0>>
or like this
<UILabel: 0x179ed0; frame = (101 0; 32 27); text = OFF ; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x179f40>>
I am not able to get the problem, because the same variable is working showing correct values in other methods, but not working well with
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
为什么?