- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell2";
UILabel *titleLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 300, 20)];
[cell.contentView addSubview:titleLabel];
titleLabel.tag = 0011;
}
else
{
titleLabel = (UILabel *)[cell.contentView viewWithTag:0011];
}
// Configure the cell...
NSMutableString *title = [NSMutableString stringWithString:@"Customer: "];
[title appendString:[titles objectAtIndex:indexPath.row]];
titleLabel.text = title.copy;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentLeft;
titleLabel.font = [UIFont systemFontOfSize:18.0];
Run Code Online (Sandbox Code Playgroud)
我的单元格永远不会是零,而我的标题标签,因为它从未被分配,尽管我的单元格已生成.我看不出这是怎么可能的.if状态永远不会是真的,应该是第一次生成的单元格,但是我的单元格应该是按原样创建的,而不是我的titleLabel的
我查看了其他解决方案,但我找不到适合自己的解决方案.我有一个,我UIImageView
在UIScrollView
那里展示大图.
我在我的UIScrollView
以及左右滑动手势识别器中启用了捏合手势.
现在,scrollview的平移手势似乎禁用,(或损坏)滑动手势.我不想禁用水平或垂直滚动UIScrollView
,我的照片的初始缩放太大,无法禁用水平滚动.
我想要做的是当我来到UIScrollView的边缘时触发滑动手势.
这是一些代码;
- (void)viewDidLoad
{
// recognizer for pinch gestures
UIPinchGestureRecognizer *pinchRecognizer =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
[self.myScrollView addGestureRecognizer:pinchRecognizer];
[self.myScrollView setClipsToBounds:NO];
// recognizer for swipe gestures
UISwipeGestureRecognizer *recognizer;
// left and right swipe recognizers for left and right animation
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self myScrollView] addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self myScrollView] addGestureRecognizer:recognizer];
....
Run Code Online (Sandbox Code Playgroud)
我的左侧滑动处理程序,目前左右滑动没有任何其他功能
-(void)handleLeftSwipe:(UISwipeGestureRecognizer *)recognizer
{
if(!self.tableView.hidden) self.tableView.hidden = YES;
[self …
Run Code Online (Sandbox Code Playgroud) 我有两种不同的方法可以调用不同的NSURLConnections;
方法A.
NSURLConnection *serverConnection = [[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:addressOfSideWebService]] delegate:self];
Run Code Online (Sandbox Code Playgroud)
方法B.
NSURLConnection *serverConnection = [[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:addressOfMainWebService]] delegate:self];
Run Code Online (Sandbox Code Playgroud)
问题是,这两个NSURLConnections都会触发相同的委托;
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.serverData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *response = [[NSString alloc]initWithData:self.serverData encoding:NSUTF8StringEncoding];
// use data
}
Run Code Online (Sandbox Code Playgroud)
我想知道的是,我们可以标记NSURLConnections'或称为NSURLConnection的方法,以便识别我可以对其采取行动的函数或方法.
我们可以设置不同的代表,还是我应该遵循的任何其他方法?
我希望我很清楚,可以提供任何其他信息.谢谢.
我已经为我的自定义创建了一个xib文件,UIView
并将我的xib加载到我的自定义UIView
中;
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"ProductDetailView" owner:self options:nil];
self = [views objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
我不想将我的所有子视图定义为IBOutlets,所以我认为迭代子视图会更合适.
for (id subview in self.subviews) {
if ([subview isKindOfClass:[UIView class]]) {
UIView *theView = (UIView*)subview;
if (theView.tag == 16) {
// tag 16 is specific to some UIViews... do stuff
}
}
else if ([subview isKindOfClass:[UILabel class]]) {
UILabel *theLabel = (UILabel*)subview;
if (theLabel.tag == 21) {
// tag 17 is specific to some UILabels... do stuff
}
else
{
// no …
Run Code Online (Sandbox Code Playgroud) 我有一个具体CGSize
的UILabel
,我不能扩展框架,UILabel
因为它是一个多行UILabels
adjustsFontSizeToFitWidth
方法不起作用.
所以我想我应该创建一个看起来像这样的功能;
- (CGFloat)fontSizeWithText:(NSString*)text andFont:(UIFont*)font constrainedSize:(CGSize)size LBM:(UILineBreakMode)LBM
{
// check if text fits to label
CGSize labelSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(size.width, 9999) lineBreakMode:LBM];
// if not, decrease font size until it fits to the given size
while (labelSize.height > size.height) {
font = [UIFont fontWithName:font.fontName size:font.pointSize - 0.5];
labelSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(size.width, 9999) lineBreakMode:LBM];
}
return font.pointSize;
}
Run Code Online (Sandbox Code Playgroud)
用法:
// fit detail label by arranging font's size
CGFloat fontSize = …
Run Code Online (Sandbox Code Playgroud) 我正在使用a UITableViewController
,我想要做的是在下面添加一个自定义工具栏UIView
.
我已经尝试启用navigationController
(下面的代码)的工具栏,但它似乎无法正常工作.UITextField
不会调用代理,文本字段的按键不会显示在文本字段中.
使用像这样的工具栏不是我的第一选择,我想在我的UITableViewController下我的自定义视图,我可以放置我的项目,就像一个UIToolbar.(保持为UIView页脚)
码:
self.navigationController.toolbarHidden = NO;
// create toolbar objects
UITextField *inputField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 230, 31)];
inputField.backgroundColor = [UIColor clearColor];
inputField.borderStyle = UITextBorderStyleRoundedRect;
inputField.inputAccessoryView = self.navigationController.toolbar;
inputField.returnKeyType = UIReturnKeyDone;
inputField.delegate = self;
UIButton *sendButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
sendButton.titleLabel.text = @"Send";
sendButton.backgroundColor = [UIColor greenColor];
// add objects into navigation controller
self.toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithCustomView:inputField],
[[UIBarButtonItem alloc] initWithCustomView:sendButton], nil];
Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序(基本SDK:iOS5)使用Facebook SDK 3.0并使用Scrumptious应用程序(示例应用程序)作为教程.如果Facebook没有开放会话,则会以模态方式呈现登录视图控制器.但它没有以模态呈现.这是代码;
- (void)showLoginView {
UIViewController *topViewController = [self.navigationController topViewController]; // not nil, RootViewController kind of class
UIViewController *modalViewController = [topViewController modalViewController]; // nil since not modalviewcontroller exists
if (![modalViewController isKindOfClass:[FacebookLoginViewController class]]) {
FacebookLoginViewController *loginViewController = [[FacebookLoginViewController alloc] initWithNibName:@"FacebookLoginViewController" bundle:nil]; // allocated, no problem
[topViewController presentModalViewController:loginViewController animated:NO]; // not working????
} else {
FacebookLoginViewController* loginViewController = (FacebookLoginViewController*)modalViewController;
[loginViewController loginFailed];
}
}
Run Code Online (Sandbox Code Playgroud)
细节;
application:didFinishLaunchingWithOptions:
分配navigationController后调用和调用的RootViewController
该navigationController的调用viewDidLoad
方法之前showLoginView
叫showLoginView
,topViewController
是不是零(这是什么是应该是:RootViewController
)ios ×6
iphone ×6
cocoa-touch ×3
delegates ×2
objective-c ×2
uitableview ×2
frame ×1
gesture ×1
scroll ×1
swipe ×1
uilabel ×1
uiscrollview ×1