1.當你在收藏界面取消收藏的時候,一次取消多個,有些會移除不掉,還會顯示在收藏界面的cell:
因為移除收藏的時候我使用的是for回圈對其收藏狀態進行判斷,所以它每次都會進行i++,并且我的for回圈的判斷標準是傳輸陣列的count值,但是當你remove掉陣列的值后,它的count值也會發生改變,所以回圈會提前停止,導致有的值沒有被移除掉,對它的修改就是將for回圈改為while回圈:
int i = 0;
while (i < self.allTransDataArray.count) {
if ([self.allTransDataArray[i][7] isEqualToString:@"0"]) {
[self.allTransDataArray removeObjectAtIndex:i];
} else {
i++;
}
}
2.收藏系統,先收藏在點贊,當你切換到收藏界面時,點贊的狀態并沒有改變:
這是因為在收藏按鈕被點擊的時候我就將點贊的狀態添加到傳輸的陣列里了,導致后來再點擊點贊的時候,因為已經把之前的狀態添加過了,所以它的狀態不會被改變,解決方法就是更新傳輸資料的陣列,當你點擊點贊按鈕時,對傳輸陣列進行判斷,如果其不為空就使用for回圈對它進行遍歷,遍歷你當時存盤的它的相應的下標,能找的話就把這一組的值抽出來,對點贊按鈕的狀態進行改變,然后在將改變后的資料替換原位置的資料,若找不到就不對其進行操作,
- (void)pressGood:(UIButton *)button {
if (button.selected) {
button.selected = NO;
[self.goodArray replaceObjectAtIndex:button.tag withObject:@"0"];
NSString *locationString = [[NSString alloc] initWithFormat:@"%ld", (long)button.tag];
if (self.allTransDataArray != nil) {
for (int i = 0; i < self.allTransDataArray.count; i++) {
if ([self.allTransDataArray[i][5] isEqualToString:locationString]) {
self.temporaryArray = [[NSMutableArray alloc] init];
self.temporaryArray = self.allTransDataArray[i];
[self.temporaryArray replaceObjectAtIndex:6 withObject:@"0"];
[self.allTransDataArray replaceObjectAtIndex:i withObject:self.temporaryArray];
}
}
}
} else {
button.selected = YES;
[self.goodArray replaceObjectAtIndex:button.tag withObject:@"1"];
NSString *locationString = [[NSString alloc] initWithFormat:@"%ld", (long)button.tag];
if (self.allTransDataArray != nil) {
for (int i = 0; i < self.allTransDataArray.count; i++) {
if ([self.allTransDataArray[i][5] isEqualToString:locationString]) {
self.temporaryArray = [[NSMutableArray alloc] init];
self.temporaryArray = self.allTransDataArray[i];
[self.temporaryArray replaceObjectAtIndex:6 withObject:@"1"];
[self.allTransDataArray replaceObjectAtIndex:i withObject:self.temporaryArray];
}
}
}
}
}
3.網路請求資料不成功,獲取到的字典資料回傳為nil:
這個是因為獲取的網路JSON資料要一一對應,我當時是吧objective當成了陣列然后對其進行資料的獲取,所以導致獲取該部分資料的時候總會獲取不到,所以獲取的相應的字典資料就為nil,最終我將陣列改為了相應的資料問題得到解決,感謝我的學姐浪費晚上兩個小時復習時間來解決我的傻逼問題!!!
@protocol ShortCommentsModel
@end
@protocol ShortReplyToModel
@end
#import "JSONModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface ShortReplyToModel : JSONModel //被回復的評論
@property (nonatomic, copy) NSString *content; //評論
@property (nonatomic, copy) NSString *author; //作者
@end
@interface ShortCommentsModel : JSONModel
@property (nonatomic, copy) NSString *author; //作者
@property (nonatomic, copy) NSString *content; //評論
@property (nonatomic, copy) NSString *avatar; //頭像
@property (nonatomic, copy) NSString *time; //時間
@property (nonatomic, copy) NSArray<ShortReplyToModel> *reply_to; //被回復的評論
@end
@interface ShortJSONModel : JSONModel
@property (nonatomic, strong) NSArray<ShortCommentsModel> *comments;
@end
NS_ASSUME_NONNULL_END
改為:
@protocol ShortCommentsModel
@end
@protocol ShortReplyToModel
@end
#import "JSONModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface ShortReplyToModel : JSONModel //被回復的評論
@property (nonatomic, copy) NSString *content; //評論
@property (nonatomic, copy) NSString *author; //作者
@end
@interface ShortCommentsModel : JSONModel
@property (nonatomic, copy) NSString *author; //作者
@property (nonatomic, copy) NSString *content; //評論
@property (nonatomic, copy) NSString *avatar; //頭像
@property (nonatomic, copy) NSString *time; //時間
@property (nonatomic, copy) ShortReplyToModel *reply_to; //被回復的評論
@end
@interface ShortJSONModel : JSONModel
@property (nonatomic, strong) NSArray<ShortCommentsModel> *comments;
@end
NS_ASSUME_NONNULL_END
4.UILabel的左上對齊:
//.h檔案中
#import <UIKit/UIKit.h>
@interface TopLeftLabel : UILabel
@end
//.m檔案中
#import "TopLeftLabel.h"
@implementation TopLeftLabel
- (id)initWithFrame:(CGRect)frame {
return [super initWithFrame:frame];
}
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines {
CGRect textRect = [super textRectForBounds:bounds limitedToNumberOfLines:numberOfLines];
textRect.origin.y = bounds.origin.y;
return textRect;
}
-(void)drawTextInRect:(CGRect)requestedRect {
CGRect actualRect = [self textRectForBounds:requestedRect limitedToNumberOfLines:self.numberOfLines];
[super drawTextInRect:actualRect];
}
@end
用的時候直接集成這個label就好::
NSString *string=@"為了測驗label的顯示方法,所以字串的長度要長一些!!為了測驗label的顯示方法,所以字串的長度要長一些!!為了測驗label的顯示方法,所以字串的長度要長一些!!";
_label = [[TopLeftLabel alloc] initWithFrame:CGRectMake(20, 50, SCREEN_WIDTH-40, 300)];
_label.backgroundColor = [UIColor groupTableViewBackgroundColor];
_label.numberOfLines = 0;
_label.text = string;
[self.view addSubview:_label];
5.知乎日報評論自適應:
在自定義的cell中對UILabel不進行高度約束,它就會自適應高度,讓UILabel的高度與文字剛好一樣!!!感謝我的樹懶學姐的精心指導!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/348425.html
標籤:其他
上一篇:Android備忘錄(筆記)簡單實作有原始碼注釋詳細
下一篇:安卓部分機型調不起微信
