반응형
indexPath로 uitableViewCell을 어떻게 얻을 수 있습니까?
어떻게 얻을 수 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]
uitableviewcell을 제공합니다. 하지만 정확히 무엇을 요구 하시는지 잘 모르겠습니다! 이 코드가 있고 여전히 uitableviewcell을 얻는 방법을 묻기 때문입니다. 좀 더 많은 정보가 당신에게 답하는 데 도움이 될 것입니다 :)
ADD : 다음은 캐스트없이 동일한 것을 달성하는 대체 구문입니다.
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nowIndex];
마지막으로 다음 코드를 사용하여 셀을 얻습니다.
UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:nowIndex];
수업이 연장 되었기 때문에 UITableViewController:
@interface SearchHotelViewController : UITableViewController
그래서 self
"SearchHotelViewController"입니다.
다음은 인덱스 경로에서 사용자 지정 셀을 가져 오는 코드입니다.
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
YourCell *cell = (YourCell *)[tblRegister cellForRowAtIndexPath:indexPath];
Swift 용
let indexpath = NSIndexPath(forRow: 2, inSection: 0)
let currentCell = tblTest.cellForRowAtIndexPath(indexpath) as! CellTest
Swift 4 용 (collectionview 용)
let indexpath = NSIndexPath(row: 2, section: 0)
let cell = self.colVw!.cellForItem(at: indexpath as IndexPath) as? ColViewCell
대한 스위프트 4
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath)
I'm not quite sure what your problem is, but you need to specify the parameter name like so.
-(void) changeCellText:(NSIndexPath *) nowIndex{
UILabel *content = (UILabel *)[[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex] contentView] viewWithTag:contentTag];
content.text = [formatter stringFromDate:checkInDate.date];
}
You can use the following code to get last cell.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:lastIndexPath];
Swift 3
let indexpath = NSIndexPath(row: 0, section: 0)
let currentCell = tableView.cellForRow(at: indexpath as IndexPath)!
Swift
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
반응형
'Nice programing' 카테고리의 다른 글
Xcode6에서 장치 콘솔을 얻는 방법은 무엇입니까? (0) | 2020.11.06 |
---|---|
Vim에서 강조 표시된 클래스 및 함수 이름 (0) | 2020.11.06 |
두 어레이 사이의 교차점을 새 어레이로 어떻게 얻습니까? (0) | 2020.11.06 |
Python에서 3D 산점도를 만드는 방법은 무엇입니까? (0) | 2020.11.04 |
모든 사용자에게 내 응용 프로그램에서 만든 파일에 대한 전체 권한을 부여하는 방법은 무엇입니까? (0) | 2020.11.04 |