반응형
indexPath별로 적합한 ViewCell을 얻으려면 어떻게 해야 합니까?
어떻게 해야 하나요?UITableViewCell
타고indexPath
다음과 같이:
나는 사용합니다.UIActionSheet
확인을 클릭하면UIButton
저는 핸드폰 문자를 바꾸고 싶습니다.
속성으로 정의하는 nowIndex
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSInteger section = [nowIndex section];
NSInteger row = [nowIndex row];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
formatter.dateFormat = @"yyyy-MM-dd";
if (section == 0)
{
if (row == 0)
{
}
else if (row == 1)
{
UILabel *content = (UILabel *)[[(UITableView *)[actionSheet ] cellForRowAtIndexPath:nowIndex] viewWithTag:contentTag];
content.text = [formatter stringFromDate:checkInDate.date];
}
else if (row == 2)
{
}
}
}
}
[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex]
당신에게 적합한 뷰셀을 제공할 수 있습니다.하지만 저는 당신이 정확히 무엇을 요구하는지 잘 모르겠어요!왜냐하면 당신은 이 코드를 가지고 있고 여전히 적절한 뷰셀을 얻는 방법을 묻고 있기 때문입니다.더 많은 정보가 답변에 도움이 될 것입니다 :)
ADD: 캐스트 없이도 동일한 작업을 수행할 수 있는 대체 구문이 있습니다.
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nowIndex];
인덱스 경로에서 사용자 지정 셀을 가져오는 코드는 다음과 같습니다.
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
YourCell *cell = (YourCell *)[tblRegister cellForRowAtIndexPath:indexPath];
스위프트를 위하여
let indexpath = NSIndexPath(forRow: 2, inSection: 0)
let currentCell = tblTest.cellForRowAtIndexPath(indexpath) as! CellTest
Swift 4의 경우(수집 보기용)
let indexpath = NSIndexPath(row: 2, section: 0)
let cell = self.colVw!.cellForItem(at: indexpath as IndexPath) as? ColViewCell
마지막으로 다음 코드를 사용하여 셀을 얻습니다.
UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:nowIndex];
수업이 연장되었기 때문입니다.UITableViewController:
@interface SearchHotelViewController : UITableViewController
그래서 그.self
는 "SearchHotelViewController"입니다.
스위프트 4용
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath)
다음 코드를 사용하여 마지막 셀을 얻을 수 있습니다.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:lastIndexPath];
문제가 무엇인지 잘 모르겠지만 매개 변수 이름을 지정해야 합니다.
-(void) changeCellText:(NSIndexPath *) nowIndex{
UILabel *content = (UILabel *)[[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex] contentView] viewWithTag:contentTag];
content.text = [formatter stringFromDate:checkInDate.date];
}
스위프트 3
let indexpath = NSIndexPath(row: 0, section: 0)
let currentCell = tableView.cellForRow(at: indexpath as IndexPath)!
스위프트
let indexpath = IndexPath(row: 0, section: 0)
if let cell = tableView.cellForRow(at: indexPath) as? <UITableViewCell or CustomCell> {
cell.backgroundColor = UIColor.red
}
언급URL : https://stackoverflow.com/questions/2384435/how-can-i-get-a-uitableviewcell-by-indexpath
반응형
'sourcecode' 카테고리의 다른 글
JTDS를 사용하여 Spring Boot에서 HikariCP 구성 (0) | 2023.08.01 |
---|---|
jQuery 요소 내에서 마우스 위치 가져오기 (0) | 2023.08.01 |
UI 세그먼트 컨트롤을 사용하여 보기를 전환하는 방법은 무엇입니까? (0) | 2023.08.01 |
Angular2 재료 대화상자 자체 닫기 (0) | 2023.08.01 |
이름을 가진 커서가 이미 존재하는 이유는 무엇입니까? (0) | 2023.08.01 |