많은 사람들이 이전에이 문제를 겪었으며 많은 제안 솔루션을 읽었으며 그 중 아무 것도 해결되지 않았습니다. 저는 세 가지보기가 포함 된 더 큰 프로젝트의 일부를 진행하고 있습니다. 첫 번째보기에는 WeekdaySelectionWithPopoverCellController
이라는 사용자 정의 셀이있는 UITableView
이 포함되어 있습니다. 이 셀에는 평일 (월요일부터 금요일까지)을 나타내는 레이블 UISwitch
과 스위치 상태에 따라 각각 표시되거나 숨겨지는 다음 요소가 들어 있습니다. 스위치가 켜져 있으면, 셀은 다음과 같습니다메시지가 할당 취소 된 인스턴스 (아마도 UITableViewCell)로 전송되었습니다.
----------------------------------------------------------------------
| Monday [ON/off] between (N/A) and (N/A) |
----------------------------------------------------------------------
를 그것이 다음과 같습니다 떨어져 있다면 :
----------------------------------------------------------------------
| Monday [on/OFF] |
----------------------------------------------------------------------
(N/A) 요소 UIButtons됩니다. 사용자가 해당 버튼 중 하나를 누르면 날짜 선택 도구가있는 UIPopover
이 열립니다. 아이디어는 사용자 대신에 (N/A)의 UIButtons 표시되어야 선택기에서 시간을 선택하는 것이다 :
----------------------------------------------------------------------
| Monday [ON/off] between (12:30) and (16:00) |
----------------------------------------------------------------------
의 디스플레이 않는 한 UISwitch 작동 타격의 요소의 숨김 popover. 그러나, 사용자가 팝 오버에서 "완료"버튼을 명중하고, 팝 오버는 다음과 같은 오류와 응용 프로그램 충돌이 기각되는 경우 :
-[UITableViewCell isKindOfClass:]: message sent to deallocated instance 0xf42a100
가 이상하게 isKindOfClass을 호출하는 코드를 포함하는 유일한 장소가 ModalTableViewController
입니다 (부모보기 Popover 및 사용자 정의 셀) 및 표시되는 인스턴스의 주소는 해당 셀에 속하지 않습니다. 또한 사용자 지정 셀 (WeekdaySelectionWithPopoverCellController
)의 클래스를 벗어나는 popover의 주소도 아닙니다. 내가 NSZombieEnabled
, MallocStackLoggingNoComp
및 NSAutoreleaseFreedObjectCheckEnabled
하지만 컴파일러를 사용하도록 설정 한
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// crashes:
int retVal = UIApplicationMain(argc, argv, nil, nil); // <--
[pool release];
return retVal;
}
:
@implementation ModalTableViewController
@synthesize mtvcNavigationBar;
@synthesize mtvcTableView;
@synthesize cell;
@synthesize lable;
@synthesize button;
// WeekdaySelectionWithPopoverCell
@synthesize wswpMainLabel;
@synthesize wswpFromLabel;
@synthesize wswpToLabel;
@synthesize wswpOClockFromLabel;
@synthesize wswpOClockToLabel;
@synthesize wswpSwitch;
@synthesize wswpFromValueButton;
@synthesize wswpToValueButton;
@synthesize popoverController;
// more code...
- (ModalTableViewController *)initWithParam:(NSString *)title andData:(NSArray *)myData andSelection:(NSArray *)selection {
[self initSwipeLeftNavigation];
mtvcNavigationBar.topItem.title = title;
mtvcSectionSize = [myData count];
mtvcSectionname = @"";
mtvcLabels = myData;
mtvcData = selection;
[mtvcLabels retain];
[mtvcData retain];
[otherValues retain];
mtvSingleton = [ModalTableViewSingleton sharedInstance];
return self;
}
// more code...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cellRet;
NSString *MyIdentifier = @"WeekdaySelectionWithPopoverCellController";
cellRet = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cellRet == nil) {
[[NSBundle mainBundle] loadNibNamed:MyIdentifier owner:self options:nil];
cellRet = self.cell;
}
NSDictionary *tempValues;
tempValues = [mtvcData objectAtIndex:indexPath.row];
wswpSwitch = (UISwitch *)[cellRet viewWithTag:2];
wswpSwitch.on = [[tempValues valueForKey:@"company_id"] isKindOfClass:[NSNull class]] ? false: true;
BOOL negatedState = !wswpSwitch.on;
NSLog(@"tempValues: %@", tempValues);
lable = (UILabel *)[cellRet viewWithTag:1];
lable.text = [NSString stringWithFormat:@"%@", [tempValues valueForKey:@"short"]];
lable.font = [UIFont boldSystemFontOfSize:16];
lable = (UILabel *)[cellRet viewWithTag:3];
lable.font = [UIFont boldSystemFontOfSize:16];
lable.text = [NSString stringWithFormat:@"%@", @"von"];
lable.hidden = negatedState;
lable = (UILabel *)[cellRet viewWithTag:5];
lable.text = [NSString stringWithFormat:@"%@", @"bis"];
lable.font = [UIFont boldSystemFontOfSize:16];
lable.hidden = negatedState;
lable = (UILabel *)[cellRet viewWithTag:7];
lable.text = @"Uhr";
lable.font = [UIFont boldSystemFontOfSize:16];
lable.hidden = negatedState;
lable = (UILabel *)[cellRet viewWithTag:8];
lable.text = @"Uhr";
lable.font = [UIFont boldSystemFontOfSize:16];
lable.hidden = negatedState;
button = (UIButton *)[cellRet viewWithTag:4];
[self setButtonLabel:button forKey:@"beginning" fromDict:tempValues];
button.hidden = negatedState;
/*
if (![[tempValues valueForKey:@"beginning"] isKindOfClass:[NSNull class]]) {
button.titleLabel.text = [NSString stringWithFormat:@"%@", [tempValues valueForKey:@"beginning"]];
} else {
button.titleLabel.text = @"k.A.";
}
*/
button = (UIButton *)[cellRet viewWithTag:6];
[self setButtonLabel:button forKey:@"until" fromDict:tempValues];
button.hidden = negatedState;
/*
if (![[tempValues valueForKey:@"until"] isKindOfClass:[NSNull class]]) {
button.titleLabel.text = [NSString stringWithFormat:@"%@", [tempValues valueForKey:@"until"]];
} else {
button.titleLabel.text = @"k.A.";
}
*/
self.cell = nil;
return cellRet;
}
- (void)setButtonLabel:(UIButton *)btn forKey:(NSString *)key fromDict:(NSDictionary *)dict {
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
NSString *text = [dict objectForKey:key];
if ([mtvSingleton.sharedData objectForKey:key]) {
[btn setTitle:[mtvSingleton.sharedData objectForKey:key] forState:UIControlStateNormal];
} else {
if ([text isKindOfClass:[NSNull class]] ||
[text isEqualToString:@""])
{
[btn setTitle:@"k.A." forState:UIControlStateNormal];
} else {
[btn setTitle:text forState:UIControlStateNormal];
}
}
}
// more code...
- (IBAction)switchButtonValueChanged:(id)sender
{
//[self changeDisplayState:wsdSwitch.on forObj:sender];
// UISwitch *tmp = (UISwitch *)sender;
UIView *v = (UIView *)sender;
do {
v = v.superview;
} while (![v isKindOfClass:[UITableViewCell class]]);
// WeekdaySelectionWithPopoverCellController *cell1 = (WeekdaySelectionWithPopoverCellController *)v;
cell = (UITableViewCell *)v;
wswpSwitch = (UISwitch *)[cell viewWithTag:2];
BOOL negatedState = !wswpSwitch.on;
lable = (UILabel *)[cell viewWithTag:3];
lable.hidden = negatedState;
lable = (UILabel *)[cell viewWithTag:5];
lable.hidden = negatedState;
lable = (UILabel *)[cell viewWithTag:7];
lable.hidden = negatedState;
lable = (UILabel *)[cell viewWithTag:8];
lable.hidden = negatedState;
button = (UIButton *)[cell viewWithTag:4];
button.hidden = negatedState;
button = (UIButton *)[cell viewWithTag:6];
button.hidden = negatedState;
/*
wswpSwitch = (UISwitch *)[cell1 viewWithTag:2];
BOOL negatedState = !wswpSwitch.on;
lable = (UILabel *)[cell1 viewWithTag:3];
lable.hidden = negatedState;
lable = (UILabel *)[cell1 viewWithTag:5];
lable.hidden = negatedState;
lable = (UILabel *)[cell1 viewWithTag:7];
lable.hidden = negatedState;
lable = (UILabel *)[cell1 viewWithTag:8];
lable.hidden = negatedState;
button = (UIButton *)[cell1 viewWithTag:4];
button.hidden = negatedState;
button = (UIButton *)[cell1 viewWithTag:6];
button.hidden = negatedState;
*/
}
#pragma mark - handlers
- (IBAction)toButtonHandler:(id)sender {
dppvc = [[DatePickerPopoverViewController alloc] initWithCaller:self andKey:@"beginning"];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:dppvc];
popover.delegate = self;
self.popoverController = popover;
[popover release];
[self.popoverController presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (IBAction)fromButtonHandler:(id)sender {
dppvc = [[DatePickerPopoverViewController alloc] initWithCaller:self andKey:@"until"];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:dppvc];
popover.delegate = self;
self.popoverController = popover;
[popover release];
CGRect senderFrameRect = [(UIButton *)sender frame];
[self.popoverController presentPopoverFromRect:senderFrameRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
#pragma mark - UIPopoverControllerDelegate
//---called when the user clicks outside the popover view---
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
// NSLog(@"popover about to be dismissed");
return YES;
}
//---called when the popover view is dismissed---
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
// NSLog(@"popover dismissed");
}
- (void)dismissPopover {
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < [mtvcLabels count]; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
[mtvcTableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:YES];
}
}
- (void)dealloc {
[mtvcSectionname release];
[mtvcLabels release];
[mtvcData release];
[cell release];
[super dealloc];
}
충돌이 main.m에서 발생
내가 당신에게 ModalTableViewController.m의 관련 부분을 드리겠습니다 내가 게시 한 것보다 더 많은 정보를 제공하지 않습니다.
저는 하루 종일이 문제를 해결하려고 노력했지만 아무 소용이 없습니다. 올바른 방향의 힌트를 주시면 감사하겠습니다!
** ** 업데이트 ** : 충돌은 [mtvcTableView reload] 또는 등의 호출 후 UITableView의 콘텐츠가 다시로드 된 후에 만 발생합니다. iPad 시뮬레이터에서 나는 popover가 사라지고 셀이 충돌하기 전에 애니메이션으로 다시로드되는 것을 볼 수 있으며 첫 번째 게시물에서 언급 한 오류를 던집니다. – TigreFurry