我有一个 UITableView,我将其添加到主视图内的 UIView。该表加载自定义单元格并加载数据并正确响应滚动,但未调用 didSelectRowAtIndexPath。如果我将表格移出其容器 UIView,则会调用 delegate 方法。
因此它仅在容器 View 内不起作用,但该 View 具有 userInteractionEnable = YES 并且表格响应滚动。
该表也设置为单选。
知道为什么它不响应选择吗? 在此先感谢您的帮助
这是一些代码:
self.table.delegate = self;
self.table.dataSource = self;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.classNames count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"ClassCell" owner:self options:nil];
cell = self.tvCell;
self.tvCell = nil;
}
//Set up custom cell
return cell;
}
//When cell is tapped
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *className = [NSString stringWithFormat:@"%@", [self.classNames objectAtIndex:indexPath.row]];
if([[AppManager sharedManager] isPad])
{
ClassWork *controller = [[ClassWork alloc] initWithNibName:@"ClassWork_iPad" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
controller.delegate = self;
[controller setClassIndex:indexPath.row];
[controller setClassTitle:[NSString stringWithString:className]];
[self presentModalViewController:controller animated:YES];
}
else
{
if([[AppManager sharedManager] is4inchScreen])
{
ClassWork *controller = [[ClassWork alloc] initWithNibName:@"ClassWork_iPhone4in" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
controller.delegate = self;
[controller setClassIndex:indexPath.row];
[controller setClassTitle:[NSString stringWithString:className]];
[self presentModalViewController:controller animated:YES];
}
else
{
ClassWork *controller = [[ClassWork alloc] initWithNibName:@"ClassWork_iPhone" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
controller.delegate = self;
[controller setClassIndex:indexPath.row];
[controller setClassTitle:[NSString stringWithString:className]];
[self presentModalViewController:controller animated:YES];
}
}
}
//Delete Cell
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// If row is deleted, remove it from the list.
if(editingStyle == UITableViewCellEditingStyleDelete)
{
[self.classNames removeObjectAtIndex:indexPath.row];
[self.classDays removeObjectAtIndex:indexPath.row];
[self.classTimes removeObjectAtIndex:indexPath.row];
//Get Corresponding File Path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:(0)];
NSString *classNum = [NSString stringWithFormat:@"Class%d", indexPath.row];
NSString *classFolder = [documentsDirectory stringByAppendingPathComponent:classNum];
//Remove Folder
[[NSFileManager defaultManager] removeItemAtPath: classFolder error: nil];
//Change numClasses
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:kNumClasses];
//Get current number
NSString *str = [[AppManager sharedManager] loadFileData:fileName];
int numClasses = [str intValue] - 1;
//Decrease by 1
str = [NSString stringWithFormat:@"%d", numClasses];
//Re-write
NSData *outFileData = [str dataUsingEncoding:[NSString defaultCStringEncoding]];
[[AppManager sharedManager] writeFileData:fileName :outFileData];
//Rename class folders
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *newFilePath;
NSString *newClassNum;
int newIndex = 0;
for(int i = 0; i < (numClasses + 1); i++)
{
classNum = [NSString stringWithFormat:@"Class%d", i];
classFolder = [documentsDirectory stringByAppendingPathComponent:classNum];
if([[NSFileManager defaultManager] fileExistsAtPath:classFolder])
{
newClassNum = [NSString stringWithFormat:@"Class%d", newIndex];
newFilePath = [documentsDirectory stringByAppendingPathComponent:newClassNum];
newIndex++;
if(classFolder != newFilePath)
{
// Rename the file by moving the file
[fileMgr moveItemAtPath:classFolder toPath:newFilePath error:nil];
}
}
}
//Reload Table
[self.table reloadData];
[self setNumberOfAssignmentsToCome];
if(numClasses == 0)
{
self.noClassesLabel1.hidden = NO;
self.noClassesLabel2.hidden = NO;
self.table.userInteractionEnabled = NO;
}
}
}
最佳答案
事实证明,有一个手势识别器吸收了所有的触摸。我将其更改为在特定时间出现,而在其他时间消失,现在表格 View 工作正常
关于iphone - UITableView 不响应选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13106264/
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
在我做的一些网络开发中,我有多个操作开始,比如对外部API的GET请求,我希望它们同时开始,因为一个不依赖另一个的结果。我希望事情能够在后台运行。我找到了concurrent-rubylibrary这似乎运作良好。通过将其混合到您创建的类中,该类的方法具有在后台线程上运行的异步版本。这导致我编写如下代码,其中FirstAsyncWorker和SecondAsyncWorker是我编写的类,我在其中混合了Concurrent::Async模块,并编写了一个名为“work”的方法来发送HTTP请求:defindexop1_result=FirstAsyncWorker.new.async.
我完全不是程序员,正在学习使用Ruby和Rails框架进行编程。我目前正在使用Ruby1.8.7和Rails3.0.3,但我想知道我是否应该升级到Ruby1.9,因为我真的没有任何升级的“遗留”成本。缺点是什么?我是否会遇到与普通gem的兼容性问题,或者甚至其他我不太了解甚至无法预料的问题? 最佳答案 你应该升级。不要坚持从1.8.7开始。如果您发现不支持1.9.2的gem,请避免使用它们(因为它们很可能不被维护)。如果您对gem是否兼容1.9.2有任何疑问,您可以在以下位置查看:http://www.railsplugins.or
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
我的Rails应用程序中安装了carrierwave。但是,当用户上传多页pdf时,我只希望应用程序获取文档中的第一页并将其转换为jpeg。这可能吗?用什么命令?这是我的uploader。#encoding:utf-8classImageUploader[200,300]##defscale(width,height)##dosomething#end#Createdifferentversionsofyouruploadedfiles:version:thumbdoprocess:resize_to_fill=>[150,210]process:convert=>:jpgdefful
对于用户模型,我有一个过滤器来检查用户的预订状态,该状态由整数值(0、1或2)表示。UserActiveAdmin索引页上的过滤器是通过以下代码实现的:filter:booking_status,as::select然而,这会导致下拉选项为0、1或2。当管理员用户从下拉列表中选择它们时,我更愿意自己将它们命名为“未完成”、“待定”和“已确认”之类的名称。有没有办法在不改变booking_status在模型中的表示方式的情况下做到这一点? 最佳答案 假设booking_status是模型中的枚举字段,您可以使用:过滤器:booking
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:HowdoIgeneratealistofnuniquerandomnumbersinRuby?我想做的事:Random.rand(0..10).timesdoputsRandom.rand(0..10)end但如果随机数已经显示过,则无法再次显示。如何最轻松地做到这一点?
当你在类中包含方法名冲突的模块时,它会使用类定义的方法。有没有办法选择我想运行的?moduleBdefself.hello"helloB"endendclassAincludeBdefself.hello"helloA"endendA.hello#=>thisprints"helloA",whatifIwant"helloB"? 最佳答案 Ben,当你在Ruby中调用一个方法(比如hello)时,会发生以下情况:如果接收者的特征类有一个名为hello的方法,它将被调用。如果不是:如果接收者的类有一个名为hello的实例方法,它将被调
在尝试解决“网格上的路径”问题时,我编写了代码defpaths(n,k)p=(1..n+k).to_ap.combination(n).to_a.sizeend代码工作正常,例如ifn==8andk==2代码返回45,这是正确的路径数。但是,当使用较大的数字时,代码非常慢,我正在努力想出如何加快这个过程。 最佳答案 与其构建组合数组只是为了计算它,不如编写function定义组合的数量。我敢肯定还有包含此功能和许多其他组合函数的gem。请注意,我使用的是gemDistribution对于Math.factorial方法,但这是另一种