UITableView don't react on a tap
I have a fully working grouped tableview. But when i just tap on a cell - nothing happens. willSelectRowAtIndexPath is not even being called. All outlets are set correctly, userInteractions are enabled, tableView is the only view on a page. Googling for hours made no success. Everyone has a selection featu开发者_开发知识库re from the begining and someone even tries to ged rid of it. Help, please.
Code (bad one, i know):
//
// VKFriendsPage.m
// vKontakte
//
// Created by ASPCartman on 3/29/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "VKFriendsPage.h"
#import "UIImage+Resize.h"
#import "VKProfilePage.h"
@implementation VKFriendsPage
@synthesize friends,onlineFriends,VKId,connection,avatarCache;
-(void) didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
NSLog(@" Memary Wornenk!!! OLOLOLOLOL!");
}
-(void)viewWillAppear:(BOOL)animated
{
table.backgroundColor=[UIColor clearColor];
if ([connection.myVkontakteID isEqual:VKId]) {
friends=[connection.myVKProfile friendsAll];
onlineFriends=[connection.myVKProfile friendsOnline];
}
self.avatarCache = [NSMutableDictionary dictionaryWithCapacity:2];
queue = [NSOperationQueue new];
table.allowsSelection=YES;
}
#pragma mark Table Data Source Protocol Implementation
//Количество строк в секции
//0ая - Ребята онлайн
//1ая - Все
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
if (section==0) {
return [onlineFriends count];
}else if (section==1) {
return [friends count];
}else {
return 0;
}
}
//Создание клеток
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Инит клетки
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"FriendCell"];
//Выбор секции
NSArray *currentMan;
if (indexPath.section==0) {
currentMan=[onlineFriends objectAtIndex:indexPath.row];
}else if (indexPath.section==1)
{
currentMan=[friends objectAtIndex:indexPath.row];
}else {
currentMan=nil;
}
cell.selectionStyle=UITableViewCellSelectionStyleBlue;
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text=[currentMan objectAtIndex:1];
cell.detailTextLabel.text=@"TODO: Статусы...";
if ([avatarCache objectForKey:[currentMan objectAtIndex:2]]==nil) {
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:indexPath,@"Path",[currentMan objectAtIndex:2],@"URLString",nil];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(fetchAvatar:)
object:dic];
[cell.imageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"profileIco" ofType:@"jpg"]]];
[queue addOperation:operation];
[operation autorelease];
}else {
[cell.imageView setImage:[avatarCache objectForKey:[currentMan objectAtIndex:2]]];
}
return [cell autorelease];
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
VKProfilePage *profilePage=[[VKProfilePage alloc] init];
profilePage.title=[tableView cellForRowAtIndexPath:indexPath].textLabel.text;
profilePage.connection=connection;
NSString *VKID;
if (indexPath.section==0) {
VKID=[[onlineFriends objectAtIndex:indexPath.row] objectAtIndex:0];
}else if (indexPath.section==1) {
VKID=[[friends objectAtIndex:indexPath.row] objectAtIndex:0];
}
profilePage.profile=[connection getProfileOf:VKID];
[self.navigationController pushViewController:profilePage animated:YES];
[profilePage release];
}
-(void)fetchAvatar:(NSDictionary *)dic
{
NSData *imageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:[dic objectForKey:@"URLString"]]];
UIImage *image=[UIImage imageWithData:imageData];
UIImage *resizedImage = [image thumbnailImage:70 transparentBorder:0 cornerRadius:5 interpolationQuality:kCGInterpolationHigh];
[avatarCache setObject:resizedImage forKey:[dic objectForKey:@"URLString"]];
[self performSelectorOnMainThread:@selector(updateRow:) withObject:[dic objectForKey:@"Path"] waitUntilDone:NO];
}
-(void)updateRow:(NSIndexPath *) ip
{
[table reloadRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationNone];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
{
return NO;
};
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section==0) {
return @"Online";
}else {
return @"Offline";
}
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return nil;
};
@end
Did you implement something like this in your UITableView
delegate?
- (BOOL)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
Sorry, wrong assumption and a compiler warning ignored...
This is not the solution.
I did some experiments and found the property isUserInteractionEnabled
on the UITableView
View
ancestor. If set to NO
, the cell selection is disabled (as is any other interaction). In this case it is impossible to move the views cells up and down.
精彩评论