여기 코드의 내 관련 비트입니다 메서드 호출에 응답하지 않는 것은대리인이
이이 내 changeDaysViewController.m의 방법이다
@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.h입니다
-(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");
}
편집 한 이 내가 UITableView
의 스위치를 변경하면 여기에 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;
}
입니다 나는 테이블보기 방법에서 콘솔에 "is on changed is 1"
을 기록합니다. -(void) updateSwitch
. 그러나 내 AddSiteViewController있는 -(void)didChangeDays
메서드에서 아무 일도 발생하지 않습니다. 내가 뭘 잘못하고 있니? 당신의 changeDaysViewController.h에서
그래서'NSLog (@ "일이
addsiteViewController의 콘솔 출력이 없지만 changedaysViewController –
의 콘솔이 있습니다. daysoftheweekViewController를 어딘지에 자식보기 컨트롤러로 추가하고 있습니까? – Corey