objective-c 遍历表格的方法0+

44,493 views / 2011.08.25 / 9:09 下午
for (int i = 0; i < [ptableView numberOfSections]; i++) {
    for (int j = 0; j < [ptableView numberOfRowsInSection:i]; j++) {
        NSUInteger ints[2] = {i,j};
        NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:ints length:2];
            UITableViewCell *cell = [ptableView cellForRowAtIndexPath:indexPath];
           //Here is your code
 
    }
}

希望对你有帮助。

Categories: 感悟 Tags: ,

最近开发的乐助理360应用, 初次使用需要手机接受一条包含激活码的短信,  用户输入正确激活码后才能使用改应用. 所有的事情都做好了,杜工非常期待的提交给了苹果审核,结果人家给rejected了,原因是”我们收不到你们国家的短信,没法测试”,原文如下:

We began the review of your app but are not able to continue because we need demo phone number and verification code to fully access your app features. Please ensure that the demo account you provide includes any data necessary to demonstrate the functionality of your app features.

我了个去, 杜工怎么之前就没想到这点呢?于是一顿穷改, 加了一个固定的测试号码,只要输入这个号码,系统返回的激活码都是固定的就行了. 最后,重新提交审核,在review notes中客客气气的作下说明:

I’m sorry that our sms platform couldn’t send message to your country. So I added a special account as you mentioned in resolution center: 手机号码:130******* 激活码1234 So as long as you entered this phone No. exactly, the active code will always be 1234.
For that and some bug-fixed, I upload a new binary. Thank’s for your kindly help and best regards.

Categories: 感悟 Tags:

为iphone数字键盘添加完成按钮0+

56,448 views / 2011.06.25 / 9:09 下午

If you have ever written an iPhone app that requires numeric input, then you surely know about the UIKeyboardTypeNumberPad. And if you have ever used that flavor of the iPhone’s keyboard, then you surely know that it lacks one very important feature: The UIKeyboardTypeNumberPad does not have a “return” key.

In fact every other keyboard type (except for the pretty similar UIKeyboardTypePhonePad) does offer the possibility to be dismissed by setting the returnKeyType property of the corresponding UITextInputTraits implementor. So how does one achieve the same effect with the number pad? We have found a workround!

When looking at the number pad, you’ll notice that there is an unused space on its bottom left. That’s where we are going to plug in our custom “return” key.

To make it short: take a screenshot, cut out the whole backspace key, flip it horizotally, clear its backspace symbol in Photoshop and overlay it with the text that we want on our “return” key. We’ve chosen to label it “DONE”. Now we have the image for our custom button’s UIControlStateNormal. Repeat the whole procedure (with a touched backspace key when taking the screenshot) to get a second image for our button’s UIControlStateHighlighted. Here’s the result:

Now back to coding. First we need to know when the number pad is going to be slided up on the screen so we can plug in our custom button before that happens. Luckily there’s a notification for exactly that purpose, and registering for it is as easy as:

 
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(keyboardWillShow:) 
                                             name:UIKeyboardWillShowNotification 
                                           object:nil];

Don’t forget to remove the observer from the notification center in the appropriate place once you’re done with the whole thing:

 
[[NSNotificationCenter defaultCenter] removeObserver:self];

Now we’re getting to the heart of it. All we have to do in the keyboardWillShow method is to locate the keyboard view and add our button to it. The keyboard view is part of a second UIWindow of our application as others have already figured out (see this thread). So we take a reference to that window (it will be the second window in most cases, so objectAtIndex:1 in the code below is fine), traverse its view hierarchy until we find the keyboard and add the button to its lower left:

 
- (void)keyboardWillShow:(NSNotification *)note {  
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            [keyboard addSubview:doneButton];
    }
}

Voilà, that’s it! The empty space for our button starts at coordinate (0, 163) and has the dimensions (106, 53). The doneButton method has to be written now of course, but that’s not hard any more. Just make sure that you call resignFirstResponder on the text field that is being edited to have the keyboard slide down.

We’re “DONE”.

 

本文例子 downloaded as Xcode project
更新: download 3.0 compatible Xcode project.
最新的: download the newest version (可运行 2.0 – 4.0所有版本)

 

来源:http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key

Categories: 分享 Tags:

问:ios开发下使用什么命令能退出iphone应用?0+

85,777 views / 2011.05.29 / 11:11 下午

There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take – turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.

WARNING: It is possible to quit the application by calling exit. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen. Such usage provides a negative experience and is strongly discouraged.

Categories: 分享 Tags:

Discuz7.2 IE9兼容性–杜工完全修补方案0+

80,727 views / 2011.04.22 / 6:06 下午
现象:
1. IE9快速发帖不跳转
2. IE9管理员处理帖子失败
3. IE9登录不跳转,需要手动刷新
原因:
1. AJAXPOST函数判断out了
2. 动态创建iframe时各浏览器处理方式不同
解决方法:
1. 修改templates/header.htm
<meta http-equiv=”x-ua-compatible” content=”ie=7″ />
替换为
<!–[if lte IE 8]>
 <meta http-equiv=”x-ua-compatible” content=”ie=7″ /> <![endif]–>
<!–[if IE 9]>
<meta http-equiv=”x-ua-compatible” content=”ie=9″ />
<![endif]–>
2.修改include/js/common.js
把ajaxpost函数替换为:
function ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
 var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
 var showidclass = !showidclass ? '' : showidclass;
 var ajaxframeid = 'ajaxframe';
 var ajaxframe = $(ajaxframeid);
 var formtarget = $(formid).target;
 
var handleResult = function() {
 var s = '';
 var evaled = false;
 
showloading('none');
 try {
 s = $(ajaxframeid).contentWindow.document.XMLDocument.text;
 } catch(e) {
 try {
 s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.wholeText;
 } catch(e) {
 try {
 s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.nodeValue;
 } catch(e) {
 s = '内部错误,无法显示此内容';
 }
 }
 }
 
if(s != '' && s.indexOf('ajaxerror') != -1) {
 evalscript(s);
 evaled = true;
 }
 if(showidclass) {
 $(showid).className = showidclass;
 if(submitbtn) {
 submitbtn.disabled = false;
 }
 }
 if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
 ajaxinnerhtml($(showid), s);
 }
 ajaxerror = null;
 if($(formid)) $(formid).target = formtarget;
 if(typeof recall == 'function') {
 recall();
 } else {
 eval(recall);
 }
 if(!evaled) evalscript(s);
 ajaxframe.loading = 0;
 $('append_parent').removeChild(ajaxframe);
 };
 if(!ajaxframe) {
 try{
 ajaxframe = document.createElement('<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '"></iframe>');
 }catch(e){
 ajaxframe = document.createElement('iframe');
 ajaxframe.name = ajaxframeid;
 ajaxframe.id = ajaxframeid;
 }
 ajaxframe.style.display = 'none';
 ajaxframe.loading = 1;
 $('append_parent').appendChild(ajaxframe);
 } else if(ajaxframe.loading) {
 return false;
 }
 
_attachEvent(ajaxframe, 'load', handleResult);
 
showloading();
 $(formid).target = ajaxframeid;
 $(formid).action += '&inajax=1';
 $(formid).submit();
 return false;
}
后台刷新缓存,搞定。
Categories: 感悟 Tags: ,