ここに私の関連するコードがあります
これは私のchangeDaysViewController.hです
@protocol changedays <NSObject>
-(void)didChangeDays:(NSNumber *)position :(BOOL )on_off;
@end
#import "AddSiteViewController.h"
#import <UIKit/UIKit.h>
@interface daysoftheweekViewController : UITableViewController{
}
@property (retain, nonatomic)NSMutableArray *daysOfTheWeek;
@property (retain, nonatomic)NSMutableArray *daysOfTheWeekNames;
@property (assign) id<changedays>deligate;
@end
これは私のchangeDaysViewController.mのメソッドです
-(void)updateSwitch:(UIControl*)button withEvent:(UIEvent* )Event{
UISwitch *swch=(UISwitch *)button;
UITableViewCell *cell=(UITableViewCell*)swch.superview;
if ([swch isOn]) {
NSLog(@" is onchanged is %d",swch.tag);
[self.deligate didChangeDays:[NSNumber numberWithInt:cell.tag] :YES];
}else{
NSLog(@" id off row changed is %d",swch.tag);
[self.deligate didChangeDays:[NSNumber numberWithInt:cell.tag] :NO];
}
[self.deligate didChangeDays:[NSNumber numberWithInt:cell.tag] :NO];
NSLog(@" row changed is %d",swch.tag);
}
addsiteViewController.h でプロトコルを実装しました
@interface AddSiteViewController : UIViewController <CLLocationManagerDelegate,UITableViewDelegate ,UIActionSheetDelegate,changedays>{...
私が持っているaddsiteViewController.mで
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
daysoftheweekViewController *daysvc=[[daysoftheweekViewController alloc]init];
daysvc.deligate=self;
}
return self;
}
そして、私が持っています
-(void)didChangeDays:(NSNumber *)position :(BOOL)on_off{
[daysOfTheWeek replaceObjectAtIndex:[position integerValue] withObject:[NSNumber numberWithBool:on_off]];
NSLog(@"days of the week changed in delegate");
}
edit 1 ここに cellorrowatindexpath があります
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row=[indexPath row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if(cell==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UISwitch *sw= [[UISwitch alloc]initWithFrame:CGRectMake(200.0f, 5.0f, 75.0f, 30.0f)];
cell.accessoryView=sw;
sw.tag=row;
[sw addTarget:self action:@selector(updateSwitch:withEvent:) forControlEvents:UIControlEventValueChanged];
// }
cell.textLabel.text=[daysOfTheWeekNames objectAtIndex:row];
if([[daysOfTheWeek objectAtIndex:row]integerValue]==1){
UISwitch *sw=(UISwitch *)cell.accessoryView;
[sw setOn:YES];
}else{
UISwitch *sw=(UISwitch *)cell.accessoryView;
[sw setOn:NO];
}
return cell;
}
のスイッチを変更すると、テーブル ビュー メソッドからコンソールUITableView
にログオンします。ただし、私の AddSiteViewController にあるメソッドでは何も起こりません。私は何を間違っていますか?"is on changed is 1"
-(void) updateSwitch
-(void)didChangeDays