开发者

passing button id from one .m to another .m

Need to pass a button id from one .m to another and clear my table view at the same time so i can load new data in. Nothing seems to be happening, the table still contains what it was populated with on viewDidLoad and the background image does not change. Please help.

There are no warning or errors so im not sure what im doing wrong but the value of senderIdentifier in ClassTwo.h is always 0

Thank you.

in my classOne.m i have the following button action

-(IBAction) btnPushViewtabel:(id)sender{   开发者_如何学JAVA 
ClassTwo *classtwo = [[ClassTwo alloc]init];
    classtwo.myTable = nil;
classtwo.senderIdentifier = [sender tag];   
[self.view addSubview:viewtableController.view];
}

in ClassTwo.h

@interface ClassTwo : UIViewController <UITableViewDelegate, UITableViewDataSource>  {
....
int senderIdentifier; 
} 
@property (nonatomic, readwrite)  int senderIdentifier;  

in ClassTwo.m

if(senderIdentifier == 0){
  // getNewData
  //set background img1
} else {
  // getNewData
  //set background img2
}


if(mySenderIdentifier == 0){ // getNewData //set background img1 } else { // getNewData //set background img2 }

what method is this code block in?

Edit:

This Line:

classtwo.mySenderIdentifier = [sender tag];

is called after:

viewDidLoad

In other words- when you are checking it you havn't actually set it yet.

There are a number of ways to solve this but my personal preference would be to create a custom init method for classTwo like this:

-(id)initWithSenderIdentifier:(int)identifier{

if(self=[super init]){

    self.senderIdentifier = identifier;
    self.myTable = nil;

}     
return self; 

}

Or elimate the need to store the int (given that's only used to set the background once)

-(id)initWithSenderIdentifier:(int)identifier{

if(self=[super init]){

    if(identifier)//set backgroundimg1;
    else //set backgroundimg2;
    self.myTable = nil;        
}     
return self; 

}

you use it like this:

ClassTwo *classtwo = [[ClassTwo alloc] initWithSenderIdentifier:[sender tag]];

If this is helpful, please mark it was answered

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜