所以我已经在Objective-C上编程了一年多了,我似乎无法理解属性的使用.我已经在互联网上搜索了几次,但从未真正找到过很好的解释.我理解如何创建它们:
@property (something, something) something *variableName;
@syntheize variableName;
Run Code Online (Sandbox Code Playgroud)
但是我应该创建所有实例变量属性.对我而言,据我所知,这似乎是浪费代码.但是当我在线查看代码时,有时我会在一个类中看到25个属性.我认为这是浪费.我唯一一次使用它们的方法是将信息从UITableView选定的单元格传递给细节viewController.为此,我使用:
@property (copy) NSString *myString;
Run Code Online (Sandbox Code Playgroud)
你也可以解释一下:nonatomic,copy,retain,assign,等意思.
谢谢
我需要在代码中的事件上重写一个UITableView.但我尝试的一切似乎都不起作用.我试过了[self.tableView reloadData],我和代表们一起玩过.我试图实现的目标是使用不同格式的单元格呈现完全不同的UITableView.所以我需要重绘表格.任何帮助,将不胜感激.
继承我的代码:
...
if/else...
}
//Now I want to reload the tableView
[tableView reloadData]; //Isn't getting it done
NSLog(@"index = %i", index); //Always fires
tableView.delegate = self; // Didn't help
[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; // Also nothing
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是这样的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if (segmentOptions == snacks) {
cell = [[TableViewCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSLog(@"A");
} else {
cell …Run Code Online (Sandbox Code Playgroud) 我似乎无法找到有关如何使用包含fb 3.0的解析sdk打开共享对话框的信息.我能够登录Facebook并实际上找到了一种方法来发布对话框,但仍然希望有对话框,以便人们可以添加评论,它与Facebook上的图像一起出来.这就是我到目前为止所拥有的.@"publish_stream",@"publish_actions"允许我在没有对话框的情况下发布
logInController.facebookPermissions = [NSArray arrayWithObjects:@"user_about_me",@"friends_about_me",@"publish_stream",@"publish_actions", nil];
Run Code Online (Sandbox Code Playgroud)
这是要发布
PF_FBRequest *request = [PF_FBRequest requestForPostStatusUpdate:[self.Excerpt objectForKey:@"text"]];
[request startWithCompletionHandler:^(PF_FBRequestConnection *connection, id result, NSError *error){
NSLog(@"error %@",error);
}];
Run Code Online (Sandbox Code Playgroud)
我找到了从Facebook网站打开对话框的代码,但我不知道如何获取PF_Facebook对象的实例,以便我可以打开对话框.我可以尝试做
PF_Facebook *fb = [[PF_Facebook alloc]initWithAppId:<#(NSString *)#> andDelegate:<#(id<PF_FBSessionDelegate>)#>;
Run Code Online (Sandbox Code Playgroud)
但这似乎不对,因为我已经在appdelegate初始化了这个
//更新我可以使用此代码获取对话框
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Facebook SDK for iOS", @"name",
@"Build great social apps and get more installs.", @"caption",
@"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", @"description",
@"https://developers.facebook.com/ios", @"link",
@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png", @"picture",
nil];
//publishes text on facebook
PF_FBSession …Run Code Online (Sandbox Code Playgroud) 好的,所以我想在我的应用程序中添加撤消某些操作的功能。我本来打算用自己的协议或类似的东西来创建一种方法,但是后来我发现了NSUndoManager。我想使用内置的基础方式,但似乎无法弄清楚。我需要撤消多次掷骰子的操作,因此,如果我可以存储以前的掷骰,因为的对象NSArray可能是最好的。我可以使用NSMutableString,但最好使用数组。
然后,我知道您可以摇晃以撤消操作,但是我希望有一个按钮。这些一直给我带来最大的麻烦。我在下面列出了我的尝试。这些都不起作用。任何帮助,将不胜感激。
在viewDidLoad中:
undoManager = [[NSUndoManager alloc] init];
Run Code Online (Sandbox Code Playgroud)
然后在掷骰子的方法中,我尝试了:
[[undoManager prepareWithInvocationTarget:self] undoButton];
[[undoManager prepareWithInvocationTarget:self]
[[undoManager prepareWithInvocationTarget:self] setString:[NSString stringWithFormat:@"%i", dice1num]];
setStrings:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%i", dice1num]
[NSString stringWithFormat:@"%i", dice1num],
[NSString stringWithFormat:@"%i", dice1num],
[NSString stringWithFormat:@"%i", dice1num],
[NSString stringWithFormat:@"%i", dice1num], nil]];
[[undoManager prepareWithInvocationTarget:@selector()];
[undoManager setActionName:@"A roll"];
Run Code Online (Sandbox Code Playgroud)
然后是链接到撤消按钮的IBAction:
-(IBAction)undoButton{
[undoManager undo];
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我想创建一个直到日期的天数倒计时.我对几小时或几分钟不感兴趣,只是从当前日期到设定日期的天数.这就是我一直在尝试的:
NSDate *date = [NSDate date];
NSString *dateString = [date description];
// this **dateString** string will have **"yyyy-MM-dd HH:mm:ss +0530"**
// NSMutableString *mutString = dateString;
NSArray *arr = [dateString componentSeperatedByString:@" "];
// arr will have [0] -> yyyy-MM-dd, [1] -> HH:mm:ss, [2] -> +0530 (time zone)
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为当前日期是以分钟和秒为单位的时间.
//NSDate *currentDate = [[NSDate alloc] init];
NSString *start = [arr objectAtIndex:0];//[NSString stringWithFormat:@"%@", currentDate];//@"2011-11-05";
NSLog(@"%@",start);
NSString *end = @"2011-6-03";
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd"];
NSDate *startDate = [f dateFromString:start];
NSDate *endDate …Run Code Online (Sandbox Code Playgroud) 好的,所以我试图检查一个对象是否NSArray等于用户输入的对象UITextField.它应该工作,但由于某种原因它不应该.这是我的代码:
if (theAnswer.text == [correctAnswers objectAtIndex:problemNumber]) {
NSLog(@"CORRECT");
}
else {
NSLog(@"wrong");
}
Run Code Online (Sandbox Code Playgroud)
控制台总是给错.我把这个登录:
NSLog(@"%@ %@", theAnswer.text, [correctAnswers objectAtIndex:problemNumber]);
Run Code Online (Sandbox Code Playgroud)
我明白了 A A
wrong
每次打印.谢谢您的帮助
所以我有一个UITableView,我用table中的数据填充tableview .plist.这对我来说一直很好,直到今天,当我试图做同样的事情,我无法得到numberOfRowsInSection,方法工作.这是我的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if...
else if (segmentOptions == exchange){
NSArray *array = [NSArray arrayWithArray:[exchangeDictionary objectForKey:[listOfExchanges objectAtIndex:section]]];
return [array count];
}
//Else
return contentArray.count;
}
Run Code Online (Sandbox Code Playgroud)
因此,在该代码中,每次运行代码时,代码都会崩溃.但是,我使用基本相同的代码来设置tableview文本,并且工作正常:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
if...
else if (segmentOptions == exchange) {
NSArray *array = [NSArray arrayWithArray:[exchangeDictionary objectForKey:[listOfExchanges objectAtIndex:indexPath.section]]];
cell.textLabel.text = …Run Code Online (Sandbox Code Playgroud) 我有一个电话号码格式化为易于阅读的电话号码,即 (123) 123-4567
但是,当我想在代码中使用该电话号码时,我需要将该字符串解析为数字变量(例如int)
但是,[string intValue]; 不起作用 - 我intValue在以前的项目中使用了大约一百万次,都没有问题,但是在这里,我传入的每个字符串,我得到相同的,随机int退出:
- (int)processPhoneNumber:(NSString *)phoneNumber {
NSMutableString *strippedString = [NSMutableString stringWithCapacity:10];
for (int i=0; i<[phoneNumber length]; i++) {
if (isdigit([phoneNumber characterAtIndex:i])) {
[strippedString appendFormat:@"%c",[phoneNumber characterAtIndex:i]];
}
}
NSLog(@"clean string-- %@", strippedString);
int phoneNumberInt = [strippedString intValue];
NSLog(@"**** %d\n &i", phoneNumberInt, phoneNumberInt);
return phoneNumberInt;
}
Run Code Online (Sandbox Code Playgroud)
然后当我调用这个方法时:
NSLog(@"%i", [self processPhoneNumber:self.phoneNumberTextField.text]);
Run Code Online (Sandbox Code Playgroud)
我明白了:2147483647. 我给这个方法的每个输入都返回:2147483647
cocoa-touch objective-c type-conversion phone-number nsstring
在这里,我坚持使用以下代码块
self.isFiltered?[self.filteredCategories count]:[self.categories count]
Run Code Online (Sandbox Code Playgroud)
这里isFiltered是一个bool,filteredCategories是一个可变数组,categories是一个数组.该行返回一个整数.我不明白这条线的作用和方式.谢谢
iphone ×6
ios ×5
objective-c ×5
ipad ×2
nsstring ×2
uitableview ×2
cocoa-touch ×1
facebook ×1
foundation ×1
nsarray ×1
nsdate ×1
phone-number ×1
properties ×1
share ×1
tableview ×1
uiview ×1
undo ×1
xcode ×1