ARC를 사용하도록 프로젝트를 변환 할 때 “스위치 케이스가 보호 범위에 있음”은 무엇을 의미합니까? Xcode 4 편집-> 리 팩터-> Objective-C ARC로 변환을 사용하여 ARC를 사용하도록 프로젝트를 변환하고 있습니다 … 내가 얻는 오류 중 하나는 스위치의 “일부”에서 “스위치 케이스가 보호 범위에 있습니다”입니다. 스위치 케이스.
편집, 코드는 다음과 같습니다.
오류는 “기본”경우에 표시됩니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"";
UITableViewCell *cell ;
switch (tableView.tag) {
case 1:
CellIdentifier = @"CellAuthor";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[prefQueries objectAtIndex:[indexPath row]] valueForKey:@"queryString"];
break;
case 2:
CellIdentifier = @"CellJournal";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[prefJournals objectAtIndex:[indexPath row]] valueForKey:@"name"];
NSData * icon = [[prefJournals objectAtIndex:[indexPath row]] valueForKey:@"icon"];
if (!icon) {
icon = UIImagePNGRepresentation([UIImage imageNamed:@"blank72"]);
}
cell.imageView.image = [UIImage imageWithData:icon];
break;
default:
CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
break;
}
return cell;
}
답변
각 케이스 자체를 중괄호로 묶습니다 {}
. 문제를 해결해야합니다 (내 프로젝트 중 하나에서 저를 위해).
답변
코드를 보지 않고는 확실하지 않지만 스위치 내부에 변수 선언이 있고 컴파일러가 필요한 할당 취소 지점에 대한 명확한 경로가 있는지 알 수 없습니다.
답변
이 문제를 해결하는 두 가지 쉬운 방법이 있습니다.
- 아마도 변수를 선언하고있을 것입니다. 변수 선언을 switch 문 외부로 이동
- 전체 대괄호를 중괄호 {} 사이에 넣으십시오
변수가 해제 될 때 컴파일러가 코드 행을 계산할 수 없습니다. 이 오류가 발생했습니다.
답변
나를 위해, 스위치 중간에서 문제가 시작되었고 {} IN ALL 이전 사례 설명을 포함하지 않으면 중괄호가 해결되지 않았습니다. 나에게 진술을 할 때 오류가 발생했다.
NSDate *start = [NSDate date];
이전의 경우. 이것을 삭제 한 후 모든 후속 사례 설명이 보호 범위 오류 메시지에서 깨끗해졌습니다.
답변
전에:
case 2:
NSDate *from = [NSDate dateWithTimeIntervalSince1970:1388552400];
[self refreshContents:from toDate:[NSDate date]];
break;
NSDate 정의를 전환하기 전에 옮기고 컴파일 문제를 해결했습니다.
NSDate *from; /* <----------- */
switch (index) {
....
case 2:
from = [NSDate dateWithTimeIntervalSince1970:1388552400];
[self refreshContents:from toDate:[NSDate date]];
break;
}
답변
스위치 외부의 변수를 선언 한 다음 케이스 내부에서 변수를 인스턴스화하십시오. Xcode 6.2를 사용하여 완벽하게 작동했습니다.
답변
default:
CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
***initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];***
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
break;
}
참고 : 확인하십시오! 굵고 기울임 꼴로 표시된 구문입니다. 그것을 수정하면 갈 수 있습니다.
