我有一个自定义的UIButton,UILabel被添加为子视图.按钮仅在我触摸顶部边界约15个点时执行给定选择器.当我在该区域上方点击时,没有任何反应.
我发现它不是由于按钮和标签的错误创建造成的,因为在我将按钮向下移动约15 px后,它正常工作.
更新我忘了说位于UINavigationBar下面的按钮和按钮上半部分的1/3没有触摸事件.
带有4个按钮的视图位于NavigationBar下方.当触摸顶部的"篮球"时,BackButton会触摸事件,当触摸顶部的"Piano"时,则右边的BarButton(如果存在)触摸.如果不存在,则什么也没发生.
我没有在App文档中找到这个记录的功能.
我也发现这个话题与我的问题有关,但也没有答案.
我需要在UITableViewStyleGrouped表中创建自定义单元格.如果在没有截断的情况下显示textLabel和detailTextLabel,则必须看起来像UITableViewCellStyleValue1;如果在Value1样式中标签之一,则必须看作UITableViewCellStyleSubtitle(但是带有detailTextLabel width = contentView.frame.size.width和UITextAlignmentRight)被截断.
我需要在方法中知道cell.contentView的宽度,- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath以确定单元格的高度.我比较了cell.contentView.width和标签宽度之和(我得到它们使用方法sizeThatFits:)来决定它.
那么,如何在创建单元格之前获得正确的cell.contentView.frame.size.width?
UPD:一些代码来澄清问题.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat cellHeight = 44;
CGSize textSize = [[arrayOfTextData objectAtIndex:indexPath.row]
sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:CGSizeMake( 1000, 100)
lineBreakMode:UILineBreakModeCharacterWrap];
CGSize detailedTextSize = [[arrayOfDetailTextData objectAtIndex:indexPath.row]
sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:CGSizeMake(1000, 100)
lineBreakMode:UILineBreakModeCharacterWrap];
if (textSize.width + detailedTextSize.width > /* I need here cell.contentView.frame.size.width*/ 300) {
cellHeight = textSize.height + detailedTextSize.height;
}
return cellHeight;
}
Run Code Online (Sandbox Code Playgroud)
UPD2:问题是,当我创建单元格时,cell.contentView.frame.size.width等于cell.frame.size.width并且等于320,但是在单元格出现后,cell.contentView.frame.size.width会依赖于tableView而发生变化width和tableView样式.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString …Run Code Online (Sandbox Code Playgroud) 我昨天遇到了问题.我想System.Drawing.Color在Android和iOS项目中使用结构.Xamarin文档声称MonoTouch框架具有System.Drawing.Color结构(链接 - http://iosapi.xamarin.com/?link=T:System.Drawing.Color).但是在monotouch.dll命名空间System.Drawing中没有名称为Color的结构.

我做错了什么?
我尝试将CGRect传递给NSInvocation(setArgument:atIndex :).我用NSValue包装它,推送到NSArry,然后从NSArray获取并使用NSValue(getValue :).调用(getValue :)方法会导致更改前声明的索引NSInteger i.任何人都可以说为什么会这样?
NSString className = @"UIButton";
Class cls = NSClassFromString(className);
cls pushButton5 = [[cls alloc] init];
CGRect rect =CGRectMake(20,220,280,30);
NSMethodSignature *msignature1;
NSInvocation *anInvocation1;
msignature1 = [pushButton5 methodSignatureForSelector:@selector(setFrame:)];
anInvocation1 = [NSInvocation invocationWithMethodSignature:msignature1];
[anInvocation1 setTarget:pushButton5];
[anInvocation1 setSelector:@selector(setFrame:)];
NSValue* rectValue = [NSValue valueWithCGRect:rect];
NSArray *params1;
params1= [NSArray arrayWithObjects:rectValue,nil];
id currentVal = [params1 objectAtIndex:0];
NSInteger i=2;
if ([currentVal isKindOfClass:[NSValue class]]) {
void *bufferForValue;
[currentVal getValue:&bufferForValue];
[anInvocation1 setArgument:&bufferForValue atIndex:i];
}else {
[anInvocation1 setArgument:¤tVal atIndex:i];
}
[anInvocation1 invoke];
Run Code Online (Sandbox Code Playgroud)
当这个(getValue:)方法实现'i'的值从2更改为类似的东西:1130102784,并且(setArgument:atIndex:)我有一个SIGABRT因为索引i超出界限. …
我需要你的帮助.我在NSInvocation'getReturnValue:'方法中遇到了一些问题.我想以编程方式创建UIButton,甚至更多,我想使用NSInvocation动态创建它,并通过NSArray传递值(这就是我包装UIButtonTypeRoundedRect的原因).
清单.
NSLog(@"Button 4 pushed\n");//this code executed when button pushed
Class cls = NSClassFromString(@"UIButton");//if exists {define class},else cls=nil
SEL msel = @selector(buttonWithType:);
//id pushButton5 = [cls performSelector:msel withObject:UIButtonTypeRoundedRect];//this code works correctly,but I want to do this by NSInvocation
//---------------------------
NSMethodSignature *msignatureTMP;
NSInvocation *anInvocationTMP;
msignatureTMP = [cls methodSignatureForSelector:msel];
anInvocationTMP = [NSInvocation invocationWithMethodSignature:msignatureTMP];
[anInvocationTMP setTarget:cls];
[anInvocationTMP setSelector:msel];
UIButtonType uibt_ = UIButtonTypeRoundedRect;
NSNumber *uibt = [NSNumber numberWithUnsignedInt:uibt_];
NSArray *paramsTMP;
paramsTMP= [NSArray arrayWithObjects:uibt,nil];
id currentValTMP = [paramsTMP objectAtIndex:0];//getParam from NSArray
NSInteger i=2;
void* bufferTMP; …Run Code Online (Sandbox Code Playgroud) objective-c ×4
nsinvocation ×2
ios ×1
ios4 ×1
iphone ×1
pointers ×1
uibutton ×1
uilabel ×1
uitableview ×1
xamarin.ios ×1