English 中文(简体)
我正在从@protocol处获得价值,但可以在UITableViewController上使用?
原标题:I am getting values from @protocol, but can t use in UITableViewController?

在增加主计长时,我宣布如下文所示为国家安保局。

   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

为什么?

最佳回答

在<代码>中: 您:

nameOfAlarm = (NSString *)n;

投射不必要,但无人受伤。 问题是,你没有保留<条码>n,并且可以把任何分钟留给你一个ling子。 你们需要这样做:

self.nameOfAlarm = n; // which is different from nameOfAlarm = n;

The dot notation is just syntactic sugar for:

[self setNameOfAlarm:n];

由于该财产的标识保留,通过<代码>synthesize为您创建的一套财产将保留<代码>名称OfAlarm(n)的新价值,并公布<代码>OfAlarm的旧价值。

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签