-1

我声明了一个NSString名为 *strKey的实例,@synthesize并且我将一个字符串值传递给它。

但是当我想将该字符串发送到另一个班级时。它给了我错误

在此处输入图像描述

这是我的代码

在此处为 strKey 分配一个值

 -(IBAction)getLocal:(UIButton *)sender
    {
        [self startDeckDownload];
        GroupDeckExpandableViewObject *objConfiguration=[[GroupDeckExpandableViewObject alloc] init];
        GroupListCell *celltest=(GroupListCell *)sender.superview.superview.superview;

        if(celltest != nil){
            celltest.viewDownload.hidden =NO;
            celltest.viewGetLocal.hidden=YES;
            //objConfiguration.vwWelcome=celltest.viewWelcome;
            objConfiguration.vwGetLocal=celltest.viewGetLocal;
            objConfiguration.vwDownLoad=celltest.viewDownload;
            strKey=[NSString stringWithFormat:@"%d",[sender tag]]; // i am assign one value to the string here.
            [delegate setGroupViewConfiguration:objConfiguration withtag:[NSString stringWithFormat:@"%d",[sender tag]]];

        }

    }

传递给另一个类(使用协议)。

-(void)setDownloadProgress:(float)progress
{

    [delegate setDownloadProgress:progress withkey:strKey];
}

这是协议方法的定义。

@protocol groupListCellDelegate<NSObject>

@optional
- (void) setGroupViewConfiguration:(id)objConfiguration withtag:(NSString *)key;
-(void)setDownloadProgress:(float)progress withkey:(NSString *)key;
@end

我在我的GroupView.m

#pragma mark - delegate method

    -(void)setGroupViewConfiguration:(id)objConfiguration withtag:(NSString *)key
    {

        [arrGroupViewConfiguration setValue:objConfiguration forKey:key];
        GroupDeckExpandableViewObject *objgetviews=[arrGroupViewConfiguration valueForKey:key];
         [tblData reloadRowsAtIndexPaths:[NSArray arrayWithObjects:objgetviews.cellIndexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
     //   [tblData reloadData];
    }

    -(void)setDownloadProgress:(float)progress withkey:(NSString *)key
    {
        NSLog(@"Reloaded...");
        progress_percent = progress;
        GroupDeckExpandableViewObject *objgetviews=[arrGroupViewConfiguration valueForKey:key];
        NSLog(@"%d",objgetviews.cellIndexPath.section);
        [tblData reloadRowsAtIndexPaths:[NSArray arrayWithObjects:objgetviews.cellIndexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
      //  [tblData reloadData];
    }

我在这里想念什么?

4

1 回答 1

2

您拥有initWithFormat您负责释放的返回对象,但您不拥有stringWithFormat返回自动释放字符串的返回对象,因此不需要释放它(如果您确实想拥有它的所有权,则必须保留它)。

因此,为了解决您的问题,请尝试像这样分配您的价值,

strKey=[[NSString alloc] initWithFormat:@"%d",[sender tag]];
于 2013-03-01T06:14:12.183 回答