我有一个完整工作的分组tableview。但是,当我只是点击一个单元格时 - 没有任何反应。 willSelectRowAtIndexPath甚至没有被调用。所有插座都设置正确,userInteractions已启用,tableView是页面上唯一的视图。谷歌搜索几个小时都没有成功。每个人都有一个从开始的选择功能,有人甚至试图摆脱它。求助。
代码(坏的,我知道):
//
// 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
答案 0 :(得分:0)
您是否在UITableView
代表中实施了类似的内容?
- (BOOL)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
抱歉,错误的假设和编译器警告被忽略了......
这不是解决方案。
答案 1 :(得分:0)
我做了一些实验,在isUserInteractionEnabled
UITableView
祖先上找到了属性View
。如果设置为NO
,则禁用单元格选择(与任何其他交互一样)。在这种情况下,无法上下移动视图单元格。